﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Text;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using AjaxControlToolkit;
using MTRC.ODMS.Model.SOM.CodeSetup;

namespace MTRC.ODMS.Web.SOM.UserControl
{
    //Add by :Zeng shunbo 2008-09-20 Last modify 2009-01-06 (actionlog issue id: 0834,0851).

    public partial class UCFirePortection : MTRC.ODMS.Web.UserControl.BaseUserControl
    {
        //Add By Gordon 20150704 U87
        public delegate void ForRestoreLoadFinish(bool can);
        public event ForRestoreLoadFinish OnForRestoreLoadFinish;

        #region some property

        public int StationEventID
        {
            get
            {
                return ViewState["StationEventID"] != null ? Convert.ToInt32(ViewState["StationEventID"]) : 0;
            }
            set
            {
                ViewState["StationEventID"] = value;
            }
        }

        /// <summary>
        /// 1:New 2:Edit
        /// </summary>
        public int Action
        {
            get
            {
                return ViewState["Action"] != null ? Convert.ToInt32(ViewState["Action"]) : 0;
            }
            set
            {
                ViewState["Action"] = value;
            }
        }

        /// <summary>
        /// Have parent
        /// </summary>
        public bool HaveParent
        {
            get
            {
                return ViewState["HaveParent"] != null ? Convert.ToBoolean(ViewState["HaveParent"]) : false;
            }
            set
            {
                ViewState["HaveParent"] = value;
            }
        }

        /// <summary>
        /// msg:SOM_ExistsOutStandingRecord
        /// </summary>
        public string msgSOM_ExistsOutStandingRecord
        {
            get
            {
                return ViewState["msgSOM_ExistsOutStandingRecord"] != null ? ViewState["msgSOM_ExistsOutStandingRecord"].ToString() : string.Empty;
            }
            set
            {
                ViewState["msgSOM_ExistsOutStandingRecord"] = value;
            }
        }
        /// <summary>
        /// Is First Call (Only used for AR).
        /// </summary>
        public bool FirstCall
        {
            get
            {
                return ViewState["FirstCall"] != null ? Convert.ToBoolean(ViewState["FirstCall"]) : false;
            }
            set
            {
                ViewState["FirstCall"] = value;
            }
        }

        /// <summary>
        /// Parent Station Event ID
        /// </summary>
        public int ParentEventID
        {
            get
            {
                return ViewState["ParentStationEventID"] != null ? Convert.ToInt32(ViewState["ParentStationEventID"]) : 0;
            }
            set
            {
                ViewState["ParentStationEventID"] = value;
            }
        }

        /// <summary>
        ///1:FireProtectionEnquiry 2:AR
        /// </summary>
        public int CalledBy
        {
            get
            {
                return ViewState["CalledBy"] != null ? Convert.ToInt32(ViewState["CalledBy"]) : 0;
            }
            set
            {
                ViewState["CalledBy"] = value;
            }
        }

        /// <summary>
        /// Parent Station Event No
        /// </summary>
        public string ParentEventNo
        {
            get
            {
                return ViewState["ParentStationEventNo"] != null ? ViewState["ParentStationEventNo"].ToString() : "";
            }
            set
            {
                ViewState["ParentStationEventNo"] = value;
            }
        }

        /// <summary>
        /// TempID
        /// </summary>
        public int TempID
        {
            get
            {
                return hdnTMPID.Value != null && hdnTMPID.Value != "" ? Convert.ToInt32(hdnTMPID.Value) : 0;
            }
            set
            {
                ViewState["TempID"] = value;
                hdnTMPID.Value = value.ToString();
            }
        }

        /// <summary>
        /// Go to other isolete url.
        /// </summary>
        public string OtherEventUrl
        {
            get
            {
                return ViewState["otherEventUrl"] != null ? ViewState["otherEventUrl"].ToString() : "";
            }
            set
            {
                ViewState["otherEventUrl"] = value;
            }
        }

        /// <summary>
        /// use ctrl can amend time.
        /// </summary>
        public bool CanAmendTime
        {
            get
            {
                return ViewState["CanAmendTime"] != null ? Convert.ToBoolean(ViewState["CanAmendTime"]) : false;
            }
            set
            {
                ViewState["CanAmendTime"] = value;
            }
        }

        public string MenuID
        {
            get
            {
                return ViewState["menuID"] != null ? ViewState["menuID"].ToString() : "";
            }
            set
            {
                ViewState["menuID"] = value;
            }
        }

        /// <summary>
        /// Station Event Firelink ID.
        /// </summary>
        public int StationEventFirelinkID
        {
            get
            {
                return ViewState["StationEventFirelInkID"] != null ? Convert.ToInt32(ViewState["StationEventFirelInkID"].ToString()) : -1;
            }
            set
            {
                ViewState["StationEventFirelInkID"] = value;
            }
        }

        /// <summary>
        /// Current Event is Void.
        /// </summary>
        public bool FlagObsolete
        {
            get
            {
                return ViewState["FlagObsolete"] != null ? Convert.ToBoolean(ViewState["FlagObsolete"]) : false;
            }
            set
            {
                ViewState["FlagObsolete"] = value;
            }
        }

        /// <summary>
        /// ReadOnly(true or false) default false
        /// </summary>
        public bool ReadOnly
        {
            get
            {
                return ViewState["ReadOnly"] != null ? Convert.ToBoolean(ViewState["ReadOnly"]) : false;
            }
            set
            {
                ViewState["ReadOnly"] = value;
            }
        }

        /// <summary>
        /// AllIsolateStationEventIDs
        /// </summary>
        public string AllIsolateStationEventIDs
        {
            get
            {
                return ViewState["IsolateStationEventIDs"] != null ? ViewState["IsolateStationEventIDs"].ToString() : "";
            }
            set
            {
                ViewState["IsolateStationEventIDs"] = value;
            }
        }

        //Event Init DateTime.
        public DateTime InitDateTime
        {
            get
            {
                return ViewState["InitDateTime"] != null ? this.ConvertToDateTime(ViewState["InitDateTime"].ToString()) : DateTime.MinValue;
            }
            set
            {
                ViewState["InitDateTime"] = value;
            }
        }

        /// <summary>
        /// current parent event complete and current event is o/s CanChangeStatus=true else CanChangeStatus=false.
        /// </summary>
        public bool CanChangeStatus
        {
            get
            {
                return ViewState["CanChangeStatus"] != null ? Convert.ToBoolean(ViewState["CanChangeStatus"]) : false;
            }
            set
            {
                ViewState["CanChangeStatus"] = value;
            }
        }

        /// <summary>
        /// Station event status id.//add at 2008-12-08
        /// </summary>
        public int EventStatusID
        {
            get
            {
                return ViewState["EventStatusID"] != null ? Convert.ToInt32(ViewState["EventStatusID"]) : 0;
            }
            set
            {
                ViewState["EventStatusID"] = value;
            }
        }
        /// <summary>
        /// add by benson 2015.07.24 U12.2
        /// </summary>
        public bool RestoreNormalStatus
        {
            get
            {
                return ViewState["RestoreNormalStatus"] != null ? Convert.ToBoolean(ViewState["RestoreNormalStatus"]) : false;
            }
            set
            {
                ViewState["RestoreNormalStatus"] = value;
            }
        }
        /// <summary>
        /// Last activety control id. issue979. add at 2009-02-18
        /// </summary>
        //public string LastControlID
        //{
        //    get
        //    {
        //        return this.hdnLastID.Value.Trim();
        //    }
        //    set
        //    {
        //        this.hdnLastID.Value = value;
        //    }
        //}

        /// <summary>
        /// store the StrStaffID by edit 
        /// JACK 2015930 for u223
        /// </summary>
        public string StrStaffID
        {
            get
            {
                return this.txtRequestByID.Text.Trim();
            }
        }
        #endregion

        #region Page Load Event

        protected void Page_Load(object sender, EventArgs e)
        {
            this.IsServerChanged = true;

            if (!IsPostBack)
            {
                txtIsolationDateTime.Attributes["readonly"] = "true";

                SetLanguage();

                Display();

                //Add By Gordon For U85 201506
                BindDefaultValueFromFireLinkPanel();
                //Add By Gordon Fix U106 20150630

                //add by benson 2015-07-02 begin
                //BindHandleBy();//delete by gordon 20150709
                //add by benson 2015-07-02 end
                //update by gordon 20151116 - update script key U23
                //Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "window.onload=function(){SetDefaultValueToRemark();};", true);
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "SetDefaultValue", "window.onload=function(){SetDefaultValueToRemark();};", true);
                //update end by gordon 20151116 - update script key U23
                // add by dylan 20151102 for u276
                this.ddlFireLink.Attributes["onchange"] = "showWaiting('" + this.ddlFireLink.ClientID + "','../../CSS/ForAdmRegWaitCursor.css','" + this.CalledBy + "');";
            }
            else
            {
                this.IsServerChanged = true;
                this.AjaxUpdateIsServerChanged();
            }

            CreateFireZoneGroupPanel();
            RemoveSameStationEventID();

            if (this.CalledBy == 1 && this.Action == 1)
            {
                //add by gordon 20151030
                bool flag = true;
                if (Request.QueryString["CalledBy"] == "3")
                {
                    int lid = -2;
                    int.TryParse(Request.QueryString["LocationId"], out lid);
                    DataTable dt = null;
                    if (DAL.Security.User.CanFunctionItemAccess("M140302_F1", this.ODMUser.UserProfileID, MenuID))//access all station.
                    {
                        dt = DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, true, Convert.ToInt16(LangCode), ODMUser.LocationID);
                    }
                    else if (DAL.Security.User.CanFunctionItemAccess("M140302_F2", this.ODMUser.UserProfileID, MenuID))//Can Access other stations.
                    {
                        dt = DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), ODMUser.LocationID);
                    }
                    if (dt != null)
                    {
                        int count = dt.Select("LocationID=" + lid.ToString()).Length;
                        flag = count > 0;
                    }
                    else
                    {
                        if (ODMUser.LocationID != lid)
                        {
                            flag = false;
                        }
                    }
                }

                //add by gordon 20150902 U70
                //if ((!new BasePage_SOM().IsValidStation(this.ODMUser.LocationID)))
                if ((!new BasePage_SOM().IsValidStation(this.ODMUser.LocationID)) || (!flag))//update by gordon 20151030
                {
                    //if (!new BasePage_SOM().IsALLOrOther(this.MenuID, "M140302_F1", "M140302_F2")) //add by gordon 20150907
                    if ((!new BasePage_SOM().IsALLOrOther(this.MenuID, "M140302_F1", "M140302_F2")) || (!flag)) //add by gordon 20150907
                    {
                        Response.Write("<script>alert('" + this.GetMessage("SOM_NotValidStation") + "');window.location.href='FireProtectionEnquiry.aspx?IsReject=1'</script>");
                        Response.End();
                    }
                }
            }
        }

        #endregion

        #region Some private function

        /// <summary>
        /// ShowOutStandingMessage
        /// add by gordon 20150708 U36
        /// </summary>
        private void ShowOutStandingMessage()
        {
            //add by gordon 20150708 U36
            string msg = CheckOutStandingRecord();
            ToolkitScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", "CheckToPopupMessage('" + msg + "')", true);
        }

        /// <summary>
        /// SetRestoreControl
        /// add by gordon 20150708 U95
        /// </summary>
        /// <param name="enabled">enabled</param>
        private void SetRestoreControl(bool enabled)
        {
            DataTable dt = MTRC.ODMS.DAL.SOM.Event.StationEventFireZoneGroupDa.GetStatusIDByCode(DAL.CommonData.GetStrVal("SOM_FireLink_MandatoryCHUBB"), 1);
            bool isSelected = false;
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (this.rblStatus.SelectedValue.Trim().Equals(dt.Rows[i][0].ToString().Trim()))
                    {
                        isSelected = true;
                    }
                }
            }
            if (isSelected)
            {
                //Add by gordon 20150707
                if (enabled)
                {
                    this.lblRestoreCHUBB.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true) + "<em>*</em>";
                    txtRestoreCHUBB.Enabled = enabled;
                    txtRestoreCHUBB.Text = txtFirelinkCoordinator.Text;
                }
                else
                {
                    //Add by gordon 20150707
                    this.lblRestoreCHUBB.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true);
                    txtRestoreCHUBB.Enabled = enabled;
                    txtRestoreCHUBB.Text = "";
                }
            }
            else
            {
                if (enabled)
                {
                    //Add by gordon 20150707
                    this.lblRestoreCHUBB.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true);
                    txtRestoreCHUBB.Enabled = enabled;
                    txtRestoreCHUBB.Text = txtFirelinkCoordinator.Text;
                }
                else
                {
                    //Add by gordon 20150707
                    this.lblRestoreCHUBB.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true);
                    txtRestoreCHUBB.Enabled = enabled;
                    txtRestoreCHUBB.Text = "";
                }
            }


            ddlRestoreHandleBy.Enabled = enabled;
            ddlRestoreHandleBy.SelectedValue = enabled ? this.ODMUser.ID.ToString() : "";
            lblRestoreHandleBy.Text = GetLabel("SOM_FireLinkRestoreHandleBy", true) + (enabled ? "<em>*</em>" : "");
        }

        /// <summary>
        /// BindRestoreHandleBy
        /// Add by gordon 20150707 U95
        /// </summary>
        private void BindRestoreHandleBy()
        {
            //update by gordon 20160124 ISU04
            //BindListControl(this.ddlRestoreHandleBy, "userID", "userName", DAL.SOM.CodeSetup.CDAssetType.getUserIDbyUserGroup(this.ODMUser.UserGroupID, Convert.ToInt16(LangCode)), true, "");
            BindListControl(this.ddlRestoreHandleBy, "userID", "userName", DAL.SOM.CodeSetup.CDAssetType.getUserIDbyUserGroup(this.ODMUser.UserGroupID, Convert.ToInt16(LangCode),this.StationEventID), true, "");
        }

        /// <summary>
        /// Can restore fire links and fire zone groups Req13.5
        /// Add by gordon 20150630
        /// </summary>
        /// <param name="fireProtectionInfo">fireProtectionInfo</param>
        private void BindForResotre(Model.SOM.Event.FireProtectionInfo fireProtectionInfo)
        {
            //Can restore fire links and fire zone groups Req13.5
            //Add by gordon 20150630

            if (DAL.Security.User.CanFunctionItemAccess("M140302_F5", this.ODMUser.UserProfileID, this.MenuID))
            {
                bool all = DAL.Security.User.CanFunctionItemAccess("M140302_F1", this.ODMUser.UserProfileID, this.MenuID);
                bool other = DAL.Security.User.CanFunctionItemAccess("M140302_F2", this.ODMUser.UserProfileID, this.MenuID);
                if (all || other)
                {
                    if (CanFindLocation(fireProtectionInfo.LocationID, all ? true : false))
                    {
                        if (fireProtectionInfo.EventStatusID < 2)
                        {
                            CanRestoreFireLinkOrZoneGroup(true);
                            if (OnForRestoreLoadFinish != null)
                                OnForRestoreLoadFinish(true);
                        }
                    }
                }
                else if (this.ODMUser.LocationID == fireProtectionInfo.LocationID)
                {
                    if (fireProtectionInfo.EventStatusID < 2)
                    {
                        CanRestoreFireLinkOrZoneGroup(true);
                        if (OnForRestoreLoadFinish != null)
                            OnForRestoreLoadFinish(true);
                    }
                }
            }
        }

        /// <summary>
        /// BindDefaultValueFromFireLinkPanel
        /// Add By Gordon For U85
        /// 201506
        /// </summary>
        private void BindDefaultValueFromFireLinkPanel()
        {
            string action = Request.QueryString["Action"];
            string fireLinkId = Request.QueryString["FireLinkID"];
            string calledBy = Request.QueryString["CalledBy"];
            string locationId = Request.QueryString["LocationId"];

            if (!string.IsNullOrEmpty(action))
            {
                if (!string.IsNullOrEmpty(calledBy))
                {
                    if (!string.IsNullOrEmpty(fireLinkId))
                    {
                        if (!string.IsNullOrEmpty(locationId))
                        {
                            if (action == "New" && calledBy == "3")
                            {
                                //Select Location
                                if (ddlStation.Items.FindByValue(locationId) != null)
                                {
                                    ddlStation.SelectedValue = locationId;
                                }

                                ddlStation_SelectedIndexChanged(null, null);

                                //Select FireLink 
                                if (ddlFireLink.Items.FindByValue(fireLinkId) != null)
                                    ddlFireLink.SelectedValue = fireLinkId;

                                //Set handle by
                                if (ddlHandledby.Items.FindByValue(this.ODMUser.ID.ToString()) != null)
                                    ddlHandledby.SelectedValue = this.ODMUser.ID.ToString();
                                //To be Complated
                            }
                        }
                    }
                }
            }
        }

        /// <summary>
        /// ShowEMOnCompletedStatus
        /// add by gordon 20150804 U146.2
        /// </summary>
        /// <param name="eventStatusID">eventStatusID</param>
        private void ShowEMOnCompletedStatus(int eventStatusID)
        {
            if (eventStatusID == 2)
            {
                DataTable dt = MTRC.ODMS.DAL.SOM.Event.StationEventFireZoneGroupDa.GetStatusIDByCode(DAL.CommonData.GetStrVal("SOM_FireLink_MandatoryCHUBB"), 1);
                bool isSelected = false;
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if (this.rblStatus.SelectedValue.Trim().Equals(dt.Rows[i][0].ToString().Trim()))
                        {
                            isSelected = true;
                        }
                    }
                }
                if (isSelected)
                {
                    this.lblRestoreCHUBB.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true) + "<em>*</em>";
                }
                this.lblRestoreHandleBy.Text = GetLabel("SOM_FireLinkRestoreHandleBy", true) + "<em>*</em>";
            }
        }

        private void Display()
        {
            //add by benson 2015.07.24 U12.2 begin
            this.RestoreNormalStatus = DAL.Security.User.CanFunctionItemAccess("M140102_F7", this.ODMUser.UserProfileID, this.MenuID);
            //add by benson 2015.07.24 U12.2 end
            //---------------Register some attribute-------------

            this.chkRestoreNormal.Attributes.Add("onclick", "return CheckIsExsitIsolate('" + GetMessage("SOM_FLECompleteCheckIsolation", this.LangCode) + "');"); //Add at 2009-02-04 TD:1132
            this.chkRestoreAll.Attributes.Add("onclick", "return ResorteAll(this,'" + this.OtherEventUrl + "','" + this.GetMessage("SOM_FireZoneGroupIsolateByOtherEvent", this.LangCode) + "','" + GetMessage("SOM_UndoneConfirm", this.LangCode) + "');");
            this.chkIsolateAll.Attributes.Add("onclick", "return CheckIsolateAll(this,'" + GetMessage("SOM_UndoneConfirm", this.LangCode) + "');");
            this.chkHandoverNot.Attributes.Add("onclick", "return chkHandoerClick(this,'" + GetMessage("SOM_CancelHandoverNoteConfirm", this.LangCode) + "');");

            //----------------------End-------------------------

            if (this.Action == 1)//new
            {
                #region new

                //-------------Event Person ID-------------

                ViewState["RequestPersonID"] = -1;//hardcode.
                ViewState["ReponsiblePersonID"] = -2;//hardcode.
                ViewState["CoordinatorPersonID"] = -3;//hardcode.
                //Add by gordon 20150707 U95
                ViewState["RestoreCHUBB"] = -4;

                //---------------End-------------------------


                //-------------Bind Controls----------

                BindStation();
                BindFireLinkStatus();
                BindReason();
                BindHandleBy();
                ddlHandledby.SelectedValue = this.ODMUser.ID.ToString();

                //------------End Bind---------------



                //---------------------------Set Page Controls Value--------------------------

                //update by gordon 20151020 U247
                //if (ddlStation.Items.FindByValue(this.ODMUser.StationID.ToString()) != null)
                //{
                //    this.ddlStation.SelectedValue = this.ODMUser.StationID.ToString();
                //}
                if (ddlStation.Items.FindByValue(this.ODMUser.LocationID.ToString()) != null)
                {
                    this.ddlStation.SelectedValue = this.ODMUser.LocationID.ToString();
                }

                BindFireLink();

                this.hdnResponsibleByType.Value = "1";
                this.chkRestoreNormal.Enabled = false; //add at 2009-02-04
                this.txtHandoverNote.Enabled = false;
                this.imgAssetLoanEventHighLight.Visible = false;

                this.imgAssetLoanEventStatusNew.Visible = false;

                this.txtIsolationDateTime.Text = this.FormatDateTime(this.InitDateTime, true);
                this.hdnInitDateTime.Value = this.FormatDateTime(this.InitDateTime, true);

                this.lblNOShow.Visible = false;

                this.EventStatusID = 0;

                this.lblGoToAdmission.Visible = false;
                this.lblParentEventNo.Visible = false;

                this.imgAssetLoanEventStatus.Visible = false;


                btnAmendEventTime_Click(null, EventArgs.Empty);

                if (this.ddlStation.Items.FindByValue("0") != null)
                {
                    this.ddlStation.Items.Remove(ddlStation.Items.FindByValue("0"));
                }

                if (HaveParent)
                {
                    this.btnSelectRequest.Visible = false;

                    this.lblNOShow.Text = this.ParentEventNo;
                    this.lblNOShow.Visible = true;

                    this.lblParentEventNo.Visible = true;
                    this.linkToAdmission.Visible = false;
                    this.lblGoToAdmission.Visible = true;
                    this.linkToAdmission.Attributes.Add("href", @"..\AdmissionRegistry\AdmissionRegistryEntry.aspx?StationEventID=" + this.ParentEventID);
                }
                else
                {
                    this.lblParentEventNo.Visible = false;
                    this.linkToAdmission.Visible = false;
                    this.lblGoToAdmission.Visible = false;
                    this.lblAdmissionRegistry.Visible = false;
                }

                //----------------------End Set------------------------


                //-------------------- From AR Setting --------------------

                if (this.CalledBy != 1)
                {
                    this.StationEventFirelinkID = -1;

                    if (FirstCall)//Would be add new temp data.
                    {
                        string xmlContent = BLL.SOM.Event.FireProtection.CreateDataSetXml(this.LangCode, this.ParentEventID);

                        if (xmlContent.Trim().Length < 1)
                        {
                            xmlContent = "<root></root>";
                        }

                        this.TempID = DAL.SOM.TempData.AddTempData(this.ODMUser.ID, this.ODMUser.Domain, xmlContent);
                    }

                    this.StationEventID = DAL.SOM.TempData.GetStationEventIDFormTempData(this.TempID);
                }

                //------------------- End From AR Setting ------------------

                if (this.ddlFireLink.Items.Count > 0)
                {
                    this.ddlFireLink.SelectedIndex = 0;
                }

                this.ddlFireLink_SelectedIndexChanged(null, EventArgs.Empty);//Ref

                //---------------- Add at 2008-12-8 ----------------------

                Model.Security.StaffInfo staffInfo = DAL.Security.Staff.GetStaffInfo(this.ODMUser.StaffInfoId);
                this.hdnResponsibleStaffOrExtPartyID.Value = staffInfo.StaffInfoID.ToString();
                this.hdnResponsibleByID.Value = staffInfo.StaffID;
                //this.txtHandledby.Text = staffInfo.StaffName;

                //--------------- End add at 2008-12-8 -------------------

                //---------------- Add at 2009-02-09 ---------------------

                if (this.ddlFireLink.Items.Count == 2)
                {
                    this.ddlFireLink.SelectedIndex = 1;
                    this.ddlFireLink_SelectedIndexChanged(this.ddlFireLink, EventArgs.Empty);
                }

                //---------------- End add at 2009-02-09 -----------------


                #endregion
            }
            else if (this.Action == 2)//edit
            {
                #region Edit

                if (this.CalledBy == 1)//From Fire Protection Entry.
                {

                    #region From Fire Protection Entry

                    //------------Bind Controls---------

                    BindStation();
                    BindFireLinkStatus();
                    BindReason();
                    //add by gordon 20150708 Req11.3
                    BindHandleBy();
                    BindRestoreHandleBy();

                    //-----------End Bind--------------



                    //--------------------Page Controls Value Setting---------------------------

                    Model.SOM.Event.FireProtectionInfo fireProtectionInfo = BLL.SOM.Event.FireProtection.GetFireProtectionByEventID(Convert.ToInt32(ViewState["StationEventID"].ToString()));

                    Model.SOM.Event.StationEventInfo CurrentStationEventInfo = DAL.SOM.Event.StationEventDa.GetStationEventInfoByID(this.StationEventID);
                    Model.SOM.Event.StationEventInfo parentStationEventInfo = DAL.SOM.Event.StationEventDa.GetStationEventInfoByID(CurrentStationEventInfo.ParentStationEventID);

                    /* Comment by jack 20150907 for U70 */
                    if (CurrentStationEventInfo.EventTypeID.ToString() != "3")
                    {
                        Response.Redirect(APJ.Util.Utility.GetHttpHost(this.Request) + "/SOM/FireProtection/FireProtectionEnquiry.aspx");
                    }
                    /***********************************/

                    if (this.ParentEventID < 1)
                    {
                        this.ParentEventID = CurrentStationEventInfo.ParentStationEventID;
                    }

                    if (this.ParentEventNo.Length < 1)
                    {
                        this.ParentEventNo = parentStationEventInfo.EventNo;
                    }

                    if (ddlStation.Items.FindByValue(fireProtectionInfo.LocationID.ToString()) != null)
                    {
                        this.ddlStation.SelectedValue = fireProtectionInfo.LocationID.ToString();
                    }

                    BindFireLink();

                    this.FlagObsolete = fireProtectionInfo.FlagObsolete;

                    //add at:2008-12-12 hzx
                    //edit by hjh 20120519 for DataReader not close
                    using (SqlDataReader reader = BLL.SOM.Event.StationEventAdmReg.GetARStationEventAmendTimeReader(this.LangCode, 1, this.StationEventID))
                    {
                        if (reader.HasRows)
                        {
                            string strColor = DAL.CommonData.GetStrVal("SOM_AmendedEventTime_Color").ToString();
                            this.btnAmendEventTime.Attributes.Add("style", "BACKGROUND-COLOR:" + strColor);
                        }
                    }

                    //add at:2008-11-21 by hzx
                    this.hdnStationEventLastUpdataTime.Value = this.FormatDateTime(CurrentStationEventInfo.LastUpdTime, true, true);
                    this.EventStatusID = CurrentStationEventInfo.EventStatusID;

                    //add at:2008-12-11
                    if (this.EventStatusID == 2) //complate
                    {
                        this.chkRestoreNormal.Checked = true;
                        this.lblCompleteRestoreTime.Text = this.FormatDateTime(CurrentStationEventInfo.EventCompleteTime, true);
                    }

                    this.lblNOShow.Text = fireProtectionInfo.EventNo;

                    if (this.ddlFireLink.Items.FindByValue(fireProtectionInfo.FirelinkID.ToString()) != null)
                    {
                        this.ddlFireLink.SelectedValue = fireProtectionInfo.FirelinkID.ToString();
                    }

                    //if (this.ddlReason.Items.FindByValue(fireProtectionInfo.IsolateReasonID.ToString()) != null) //modify at :2008-11-21
                    //{
                    //    this.ddlReason.SelectedValue = fireProtectionInfo.IsolateReasonID.ToString();
                    //}

                    FindByValueAndSelect(this.ddlReason, fireProtectionInfo.IsolateReasonID.ToString()); //add at:2008-11-21

                    this.txtHandoverNote.Text = fireProtectionInfo.HandoverNotedate;
                    this.hdnInitDateTime.Value = this.FormatDateTime(this.InitDateTime, true);
                    this.txtIsolationDateTime.Text = this.FormatDateTime(this.InitDateTime, true);
                    this.txtIsolationDuration.Text = fireProtectionInfo.EstimatedWrkHour.ToString();
                    this.lblEstimatedIsolationDate.Text = FormatDateTime(fireProtectionInfo.EventTime.AddMinutes(fireProtectionInfo.EstimatedWrkHour * 60), true);

                    this.txtRemarks.Text = fireProtectionInfo.Remark;

                    if (fireProtectionInfo.FlagHandover)
                    {
                        this.chkHandoverNot.Checked = true;
                        this.txtHandoverNote.Text = fireProtectionInfo.HandoverNotedate;
                    }
                    else
                    {
                        this.chkHandoverNot.Checked = false;
                    }

                    //Modify at 2009-01-08
                    //if (fireProtectionInfo.FlagRestore)
                    //{
                    //    this.chkRestoreNormal.Checked = true;
                    //}

                    this.rblStatus.SelectedValue = fireProtectionInfo.FireLinkStatusID.ToString();

                    /* Add by jack 20150527 for U30 */
                    DataTable dt = MTRC.ODMS.DAL.SOM.Event.StationEventFireZoneGroupDa.GetStatusIDByCode(DAL.CommonData.GetStrVal("SOM_FireLink_MandatoryCHUBB"), 1);
                    bool isSelected = false;
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (this.rblStatus.SelectedValue.Trim().Equals(dt.Rows[i][0].ToString().Trim()))
                            {
                                isSelected = true;
                            }
                        }
                    }
                    if (isSelected)
                    {
                        //update by gordon 20150806 U133
                        //this.lblFireLinkCoordinator.Text = GetLabel("SOM_FirelinkCoordinator", true) + "<em>*</em>";
                        this.lblFireLinkCoordinator.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true) + "<em>*</em>";
                    }
                    else
                    {
                        //update by gordon 20150806 U133
                        //this.lblFireLinkCoordinator.Text = GetLabel("SOM_FirelinkCoordinator", true);
                        this.lblFireLinkCoordinator.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true);
                    }
                    /********************************/


                    DateTime tempDT = this.ConvertToDate(this.FormatDateTime(fireProtectionInfo.EventCompleteTime));
                    if (tempDT.Year == 1900 && tempDT.Month == 1 && tempDT.Day == 1)
                    {
                        this.lblCompleteRestoreTime.Text = "";
                    }
                    else
                    {
                        this.lblCompleteRestoreTime.Text = this.FormatDateTime(fireProtectionInfo.EventCompleteTime, true);
                    }

                    this.StationEventFirelinkID = fireProtectionInfo.StationEventFirelInkID;

                    SetHighlightFlag(fireProtectionInfo.Highlight);

                    if (ddlFireLink.Items.FindByValue(fireProtectionInfo.FirelinkID.ToString()) != null)
                    {
                        this.ddlFireLink.SelectedValue = fireProtectionInfo.FirelinkID.ToString();
                    }

                    if (this.ddlReason.Items.FindByValue(fireProtectionInfo.IsolateReasonID.ToString()) != null)
                    {
                        this.ddlReason.SelectedValue = fireProtectionInfo.IsolateReasonID.ToString();
                        //this.FindByTextAndSelect(this.ddlReason, fireProtectionInfo.IsolateReasonID.ToString());
                    }

                    if (fireProtectionInfo.EventCompleteTime > DateTime.MinValue)
                    {
                        this.SetReadOnly(true);
                    }

                    //----------------------End Setting------------------------------



                    //--------------------Event Person Setting-----------------------

                    DataTable requestPersonList = DAL.SOM.Event.StationEventPersonDa.GetStationEventPersonFromView(this.LangCode, fireProtectionInfo.StationEventPersonID);
                    //delete by gordon 20150708 Req11.3
                    //DataTable responsiblePersonList = DAL.SOM.Event.StationEventPersonDa.GetStationEventPersonFromView(this.LangCode, fireProtectionInfo.ResponsiblePersonID);
                    DataTable coorindatorPersonList = DAL.SOM.Event.StationEventPersonDa.GetStationEventPersonFromView(this.LangCode, fireProtectionInfo.CoorindatorID);
                    //Add by gordon 20150707 U95
                    DataTable restorePersonList = DAL.SOM.Event.StationEventPersonDa.GetStationEventPersonFromView(this.LangCode, fireProtectionInfo.RestoreCHUBBID);

                    //Request by:
                    if (requestPersonList.Rows.Count > 0)
                    {
                        ViewState["RequestPersonID"] = requestPersonList.Rows[0]["StationEventPersonID"].ToString();
                        this.txtRequestByID.Text = requestPersonList.Rows[0]["MaskedStaffID"].ToString().Trim().Length > 0 ? requestPersonList.Rows[0]["MaskedStaffID"].ToString() : requestPersonList.Rows[0]["StaffID"].ToString();
                        this.txtRequestByName.Text = requestPersonList.Rows[0]["StaffName"].ToString();

                        this.txtRequestByDept.Text = requestPersonList.Rows[0]["DepartmentCompany"].ToString();
                        this.txtRequestByOU.Text = requestPersonList.Rows[0]["OrganizationUnit"].ToString();

                        this.txtRequestByContactNumber.Text = requestPersonList.Rows[0]["Tel"].ToString();

                        if (requestPersonList.Rows[0]["Tel"].ToString().Trim().Length < 1)
                        {
                            DataTable dtt = DAL.SOM.CodeSetup.CdStaffInfo.GetOneStaffInfoByStaffID(requestPersonList.Rows[0]["StaffID"].ToString());
                            if (dtt.Rows.Count > 0)
                            {
                                this.txtRequestByContactNumber.Text = dtt.Rows[0]["OfficeTel"].ToString();
                            }
                        }

                        this.hdnStaffType.Value = requestPersonList.Rows[0]["EventPersonTypeID"].ToString();
                        this.hdnRequestStaffOrExtPartyID.Value = requestPersonList.Rows[0]["StaffOrExtPartyID"].ToString();
                        this.hdnExtPartyStaffSnapShotID.Value = requestPersonList.Rows[0]["ExtPartystaffSnapShotID"].ToString();
                    }

                    //delete by gordon 20150708 Req11.3
                    //Responsible by:
                    //if (responsiblePersonList.Rows.Count > 0)
                    //{
                    //    ViewState["ReponsiblePersonID"] = responsiblePersonList.Rows[0]["StationEventPersonID"].ToString();
                    //    // this.txtHandledby.Text = responsiblePersonList.Rows[0]["StaffName"].ToString();
                    //    this.hdnResponsibleByID.Value = responsiblePersonList.Rows[0]["StaffID"].ToString();
                    //    this.hdnResponsibleByType.Value = responsiblePersonList.Rows[0]["EventPersonTypeID"].ToString();
                    //    this.hdnResponsibleStaffOrExtPartyID.Value = responsiblePersonList.Rows[0]["StaffOrExtPartyID"].ToString();
                    //}

                    //Coorindator by: jack
                    if (coorindatorPersonList.Rows.Count > 0)
                    {
                        ViewState["CoordinatorPersonID"] = coorindatorPersonList.Rows[0]["StationEventPersonID"].ToString();//hardcode.
                        this.txtFirelinkCoordinator.Text = coorindatorPersonList.Rows[0]["StaffName"].ToString();
                    }

                    //Add by gordon 20150707 U95
                    if (restorePersonList.Rows.Count > 0)
                    {
                        ViewState["RestoreCHUBB"] = restorePersonList.Rows[0]["StationEventPersonID"].ToString();
                        this.txtRestoreCHUBB.Text = restorePersonList.Rows[0]["StaffName"].ToString();
                    }

                    //---------------------------End Setting--------------------------------


                    SetRequestPersonTypeICO();//set request person type icon.

                    //-------------Event status ico setting---------------

                    this.imgAssetLoanEventStatus.Visible = true;
                    this.imgAssetLoanEventStatus.Src = this.GetEventStatusIconPath(fireProtectionInfo.EventStatusID); //add at 2008-11-14
                    this.imgAssetLoanEventStatus.Attributes["title"] = this.GetEventStatusDesc(this.EventStatusID, this.LangCode);//add at 2008-12-10
                    this.imgAssetLoanEventStatusNew.Attributes["title"] = this.GetEventStatusDesc(this.EventStatusID, this.LangCode);//add at 2008-12-10

                    //-----------------End setting----------------------




                    //------------------Visible Setting---------------------

                    this.imgAssetLoanEventStatusNew.Visible = false;

                    if (HaveParent)
                    {
                        this.lblParentEventNo.Text = parentStationEventInfo.EventNo;
                        this.lblParentEventNo.Visible = true;
                        this.linkToAdmission.Visible = true;
                        this.lblGoToAdmission.Visible = true;
                        this.linkToAdmission.Attributes.Add("href", @"..\AdmissionRegistry\AdmissionRegistryEntry.aspx?StationEventID=" + fireProtectionInfo.ParentStationEventID);
                    }
                    else
                    {
                        this.lblParentEventNo.Visible = false;
                        this.linkToAdmission.Visible = false;
                        this.lblGoToAdmission.Visible = false;
                    }

                    if (FlagObsolete)
                    {
                        this.SetReadOnly(true);
                    }

                    if (this.ParentEventID > 0)
                    {
                        this.lblGoToAdmission.Visible = true;
                    }
                    else
                    {
                        this.lblGoToAdmission.Visible = false;
                    }

                    if (this.HaveParent) //add 2008-10-24
                    {
                        this.imgAssetLoanEventHighLight.Visible = false;
                    }

                    //--------------------End Setting--------------------------

                    //-------------------- Modify at 2008-12-29 ---------------

                    if (Request.QueryString["Destroy"] != null && Request.QueryString["Destroy"].Trim().ToUpper() == "TRUE".ToUpper() && !this.HaveParent && this.EventStatusID == 1)
                    {
                        this.chkRestoreAll.Checked = true;
                        this.chkRestoreAll_CheckedChanged(null, EventArgs.Empty);
                        this.chkRestoreNormal.Checked = true;
                        this.chkRestoreNormal_CheckedChanged(null, EventArgs.Empty);
                    }

                    //-------------------- End modify at 2008-12-29 -----------

                    //add by gordon 20150708 Req11.3
                    if (fireProtectionInfo.ResponsiblePersonID > 0)
                    {
                        if (ddlHandledby.Items.FindByValue(fireProtectionInfo.ResponsiblePersonID.ToString()) == null)
                            ddlHandledby.SelectedIndex = 0;
                        else
                            ddlHandledby.SelectedValue = fireProtectionInfo.ResponsiblePersonID.ToString();
                    }

                    //add by gordon 20150708 U95
                    if (fireProtectionInfo.RestoreHandleByID > 0)
                    {
                        if (ddlRestoreHandleBy.Items.FindByValue(fireProtectionInfo.RestoreHandleByID.ToString()) == null)
                            ddlRestoreHandleBy.SelectedIndex = 0;
                        else
                            ddlRestoreHandleBy.SelectedValue = fireProtectionInfo.RestoreHandleByID.ToString();
                    }

                    //Add By gordon 20150704 U87
                    BindForResotre(fireProtectionInfo);

                    //add by benson 2015-07-06 begin
                    //this.msgSOM_ExistsOutStandingRecord = GetMessage("SOM_ExistsOutStandingRecord", this.LangCode).Replace("[#FireLink]", ddlFireLink.SelectedItem.Text);
                    //add by benson 2015-07-06 end

                    //add by gordon 20150804 U146.2
                    ShowEMOnCompletedStatus(CurrentStationEventInfo.EventStatusID);

                    #endregion
                }
                else//From AR
                {
                    #region From AR

                    BindFireLinkStatus();
                    BindStation();
                    BindReason();
                    //add by gordon 20150708 Req11.3
                    BindHandleBy();
                    //add by gordon 20150708 U95
                    BindRestoreHandleBy();

                    int stationEventID = this.StationEventID;
                    int tempID = this.TempID;
                    Model.SOM.Event.StationEventInfo stationEventInfo = DAL.SOM.Event.StationEventDa.GetStationEventForTempData(tempID, stationEventID);

                    //Add by jack 20151222 for u291 fixed if txtIsolationDateTime exist in temp data , then set IsolationDateTime=EventTime from temp data.
                    if (stationEventInfo.EventTime != null)
                    {
                        this.InitDateTime = stationEventInfo.EventTime;
                        //Add by jack 20151223 U291 The amendment history on isolation time is incorrect.
                        if (Session["AR_FireInitDateTime"]==null)
                        {
                            Session["AR_FireInitDateTime"] = stationEventInfo.EventTime;
                        }
                        //End Add by jack 20151223 U291 The amendment history on isolation time is incorrect.
                    }
                    //End add by jack 20151222 for u291 fixed if txtIsolationDateTime exist in temp data , then set IsolationDateTime=EventTime from temp data.

                    Model.SOM.Event.StationEventFirelinkInfo firelinkInfo = DAL.SOM.Event.StationEventFirelinkDa.GetStationEventForTempData(tempID, stationEventID);
                    DataTable personTable = DAL.SOM.Event.StationEventPersonDa.GetStationEventPersonFromTempData(tempID, stationEventID);
                    this.EventStatusID = stationEventInfo.EventStatusID;

                    //add at:2008-12-11
                    if (this.EventStatusID == 2) //complate
                    {
                        this.chkRestoreNormal.Checked = true;
                        this.lblCompleteRestoreTime.Text = this.FormatDateTime(stationEventInfo.EventCompleteTime, true);
                    }

                    if (this.ddlStation.Items.FindByValue(stationEventInfo.LocationID.ToString()) != null)
                    {
                        this.ddlStation.SelectedValue = stationEventInfo.LocationID.ToString();
                    }

                    BindFireLink();

                    //Issue U15:Add By Gordon 2015/05/25
                    using (SqlDataReader reader = BLL.SOM.Event.StationEventAdmReg.GetARStationEventAmendTimeReader(this.LangCode, 1, this.StationEventID))
                    {
                        if (reader.HasRows)
                        {
                            string strColor = DAL.CommonData.GetStrVal("SOM_AmendedEventTime_Color").ToString();
                            this.btnAmendEventTime.Attributes.Add("style", "BACKGROUND-COLOR:" + strColor);
                        }
                    }
                    //---------------------------------

                    //this.imgAssetLoanEventStatus.Src = this.GetEventStatusIconPath(stationEventInfo.EventStatusID);//add at 2008-11-14 //modify at 2008-12-04
                    this.imgAssetLoanEventStatusNew.Src = this.GetEventStatusIconPath(stationEventInfo.EventStatusID);//add at 2008-12-04
                    this.imgAssetLoanEventStatus.Visible = false;//add at 2008-12-04

                    if (HaveParent)
                    {
                        this.btnSelectRequest.Visible = false;

                        //this.lblParentEventNo.Text = this.ParentEventNo; //modify at 2008-12-04
                        this.lblNOShow.Text = this.ParentEventNo; //add at 2008-12-04

                        this.lblParentEventNo.Visible = true;
                        this.linkToAdmission.Visible = false;
                        this.lblGoToAdmission.Visible = true;
                        this.linkToAdmission.Attributes.Add("href", @"..\AdmissionRegistry\AdmissionRegistryEntry.aspx?StationEventID=" + this.ParentEventID);
                    }
                    else
                    {
                        this.lblParentEventNo.Visible = false;
                        this.linkToAdmission.Visible = false;
                        this.lblGoToAdmission.Visible = false;
                    }

                    this.StationEventFirelinkID = firelinkInfo.StationEventFirelInkID;
                    this.imgAssetLoanEventHighLight.Visible = false;
                    this.FlagObsolete = stationEventInfo.FlagObsolete;

                    //this.lblNOShow.Text = stationEventInfo.EventNo;//modify at 2008-12-04
                    this.lblParentEventNo.Text = stationEventInfo.EventNo; //add at 2008-12-04

                    this.txtIsolationDateTime.Text = FormatDateTime(this.InitDateTime, true);
                    this.hdnInitDateTime.Value = this.InitDateTime.ToString();
                    this.txtIsolationDuration.Text = stationEventInfo.EstimatedWrkHour.ToString();
                    float estimatedTime = txtIsolationDuration.Text.Trim().Length > 0 ? float.Parse(txtIsolationDuration.Text.Trim()) * 60 : 0f;
                    this.lblEstimatedIsolationDate.Text = this.FormatDateTime(this.InitDateTime.AddMinutes(estimatedTime), true);

                    ViewState["RequestPersonID"] = stationEventInfo.StationEventPersonID;
                    //ViewState["ReponsiblePersonID"] = firelinkInfo.ResponsiblePersonID;//delete by gordon 20150708 Req11.3
                    ViewState["CoordinatorPersonID"] = firelinkInfo.CoorindatorID != 0 ? firelinkInfo.CoorindatorID : -1;
                    ViewState["RestoreCHUBB"] = firelinkInfo.RestoreCHUBBID != 0 ? firelinkInfo.RestoreCHUBBID : -1;

                    FindByValueAndSelect(this.ddlFireLink, firelinkInfo.FirelinkID.ToString());// add at:2008-11-21
                    FindByValueAndSelect(this.ddlReason, firelinkInfo.IsolateReasonID.ToString());// add at:2008-11-21



                    if (this.ParentEventID > 0)
                    {
                        this.lblParentEventNo.Text = stationEventInfo.EventNo;
                        this.lblParentEventNo.Visible = true;
                    }
                    this.txtRemarks.Text = stationEventInfo.Remark;

                    // remove by dylan 2015
                    //this.chkHandoverNot.Checked = stationEventInfo.FlagHandover;
                    //this.txtHandoverNote.Text = stationEventInfo.HandoverNote;
                    if (this.EventStatusID == 2)
                    {
                        // add by dylan 20150923 for reopend issue u196
                        using (SqlDataReader drHandOverReader = MTRC.ODMS.DAL.SOM.Event.StationEventAdmRegDa.GetStationEventHandOver(StationEventID))
                        {
                            if (drHandOverReader.HasRows)
                            {
                                drHandOverReader.Read();
                                this.txtHandoverNote.Text = drHandOverReader["HandoverNote"].ToString();
                                this.chkHandoverNot.Checked = Convert.ToBoolean(drHandOverReader["FlagHandover"]);
                            }
                        }
                    }

                    this.lblParentEventNo.Text = stationEventInfo.EventNo;
                    //add by gordon 20150709 U95
                    this.FindByValueAndSelect(ddlRestoreHandleBy, firelinkInfo.RestoreHandleByID.ToString());

                    if (this.rblStatus.Items.FindByValue(firelinkInfo.FirelinkStatusID.ToString()) != null)
                    {
                        this.rblStatus.SelectedValue = firelinkInfo.FirelinkStatusID.ToString();
                    }

                    this.chkRestoreNormal.Checked = firelinkInfo.FlagRestore;

                    //------------------ Modify at 2008-12-18 ----------------------

                    ////if (MTRC.ODMS.DAL.COM.Util.DateTimeFromDB(firelinkInfo.RestoreTime) == DateTime.MinValue)
                    //if (firelinkInfo.RestoreTime == DateTime.MinValue) //modify at 2008-12-16
                    //{
                    //    this.lblCompleteRestoreTime.Text = "";
                    //}
                    //else
                    //{
                    //    this.lblCompleteRestoreTime.Text = this.FormatDateTime(firelinkInfo.RestoreTime, true);
                    //}


                    if (stationEventInfo.EventCompleteTime == DateTime.MinValue)
                    {
                        this.lblCompleteRestoreTime.Text = "";
                    }
                    else
                    {
                        this.chkRestoreNormal.Checked = true;
                        this.lblCompleteRestoreTime.Text = this.FormatDateTime(stationEventInfo.EventCompleteTime, true);
                    }

                    //---------------- End modify at 2008-12-18 --------------------


                    DataTable requestPersonList = DAL.SOM.Event.StationEventPersonDa.GetStationEventPersonFromView(this.LangCode, stationEventInfo.StationEventPersonID);
                    DataTable requestTable = DAL.SOM.Event.StationEventPersonDa.GetStationEventPersonFromView(this.LangCode, stationEventInfo.StationEventPersonID);
                    //delete by gordon 20150708 Req11.3
                    //DataTable reponsiableTable = DAL.SOM.Event.StationEventPersonDa.GetStationEventPersonFromView(this.LangCode, firelinkInfo.ResponsiblePersonID);
                    //add by gordon 20150708 U95
                    DataTable restoreTable = DAL.SOM.Event.StationEventPersonDa.GetStationEventPersonFromView(this.LangCode, firelinkInfo.RestoreCHUBBID.Value);

                    //request by:
                    if (requestTable.Select("StationEventPersonID=" + stationEventInfo.StationEventPersonID).Length > 0)
                    {
                        DataRow dr = requestTable.Select("StationEventPersonID=" + stationEventInfo.StationEventPersonID)[0];

                        this.txtRequestByID.Text = dr["MaskedStaffID"].ToString().Trim().Length > 0 ? dr["MaskedStaffID"].ToString() : dr["StaffID"].ToString();
                        this.hdnStaffType.Value = dr["EventPersonTypeID"].ToString();
                        this.hdnRequestStaffOrExtPartyID.Value = dr["StaffOrExtPartyID"].ToString();
                        this.txtRequestByName.Text = dr["StaffName"].ToString();

                        this.txtRequestByDept.Text = dr["DepartmentCompany"].ToString();

                        //this.txtRequestByOU.Text = dr[].ToString();
                        this.txtRequestByContactNumber.Text = dr["Tel"].ToString();
                    }

                    if (this.StationEventID > 0 && requestPersonList.Rows.Count > 0)
                    {
                        ViewState["RequestPersonID"] = requestPersonList.Rows[0]["StationEventPersonID"].ToString();
                        this.txtRequestByID.Text = requestPersonList.Rows[0]["MaskedStaffID"].ToString().Trim().Length > 0 ? requestPersonList.Rows[0]["MaskedStaffID"].ToString() : requestPersonList.Rows[0]["StaffID"].ToString();
                        this.txtRequestByName.Text = requestPersonList.Rows[0]["StaffName"].ToString();
                        this.txtRequestByDept.Text = requestPersonList.Rows[0]["DepartmentCompany"].ToString();
                        this.txtRequestByOU.Text = requestPersonList.Rows[0]["OrganizationUnit"].ToString();
                        this.txtRequestByContactNumber.Text = requestPersonList.Rows[0]["Tel"].ToString();

                        if (requestPersonList.Rows[0]["Tel"].ToString().Trim().Length < 1)
                        {
                            DataTable dtt = DAL.SOM.CodeSetup.CdStaffInfo.GetOneStaffInfoByStaffID(requestPersonList.Rows[0]["StaffID"].ToString());
                            if (dtt.Rows.Count > 0)
                            {
                                this.txtRequestByContactNumber.Text = dtt.Rows[0]["OfficeTel"].ToString();
                            }
                        }

                        this.hdnStaffType.Value = requestPersonList.Rows[0]["EventPersonTypeID"].ToString();
                        this.hdnRequestStaffOrExtPartyID.Value = requestPersonList.Rows[0]["StaffOrExtPartyID"].ToString();
                    }

                    this.txtRequestByID.Text = Request.QueryString["StatffID"] != null ? Request.QueryString["StatffID"] : "";
                    this.txtRequestByName.Text = Request.QueryString["txtRequestByName"] != null ? Request.QueryString["txtRequestByName"] : "";

                    //update by gordon 20150710 Decode depart value | orgunit instead of depart
                    //this.txtRequestByDept.Text = Request.QueryString["txtRequestByDept"] != null ? Request.QueryString["txtRequestByDept"] : "";
                    this.txtRequestByDept.Text = Request.QueryString["txtRequestByDept"] != null ? HttpUtility.UrlDecode(Request.QueryString["txtRequestByDept"]) : "";

                    this.txtRequestByOU.Text = Request.QueryString["txtRequestByOU"] != null ? Request.QueryString["txtRequestByOU"] : "";
                    this.txtRequestByContactNumber.Text = Request.QueryString["txtRequestByContactNumber"] != null ? Request.QueryString["txtRequestByContactNumber"] : "";
                    this.hdnStaffType.Value = Request.QueryString["hdnStaffType"] != null ? Request.QueryString["hdnStaffType"] : "";
                    this.hdnRequestStaffOrExtPartyID.Value = Request.QueryString["hdnRequestStaffOrExtPartyID"] != null ? Request.QueryString["hdnRequestStaffOrExtPartyID"] : "";


                    //-------------------------------Responsible by --------------------------------

                    //add by gordon 20150708 Req11.3
                    if (ddlHandledby.Items.FindByValue(firelinkInfo.ResponsiblePersonID.ToString()) == null)
                        ddlHandledby.SelectedIndex = 0;
                    else
                        ddlHandledby.SelectedValue = firelinkInfo.ResponsiblePersonID.ToString();
                    //delete by gordon 20150708 Req11.3
                    //if (personTable.Select("StationEventPersonID=" + firelinkInfo.ResponsiblePersonID).Length > 0)
                    //{
                    //    DataRow dr = personTable.Select("StationEventPersonID=" + firelinkInfo.ResponsiblePersonID)[0];

                    //    this.hdnResponsibleByType.Value = dr["EventPersonTypeID"].ToString();
                    //    //this.txtHandledby.Text = dr["StaffName"].ToString();
                    //    this.hdnResponsibleByID.Value = dr["StationEventPersonID"].ToString();
                    //    this.hdnResponsibleStaffOrExtPartyID.Value = dr["StaffOrExtPartyID"].ToString();
                    //}

                    //if (this.StationEventID > 0 && reponsiableTable.Rows.Count > 0)
                    //{
                    //    DataRow dr = reponsiableTable.Rows[0];

                    //    this.hdnResponsibleByType.Value = dr["EventPersonTypeID"].ToString();
                    //    //this.txtHandledby.Text = dr["StaffName"].ToString();
                    //    this.hdnResponsibleByID.Value = dr["StationEventPersonID"].ToString();
                    //    this.hdnResponsibleStaffOrExtPartyID.Value = dr["StaffOrExtPartyID"].ToString();
                    //}

                    if (personTable.Select("StationEventPersonID=" + firelinkInfo.CoorindatorID).Length > 0)
                    {
                        DataRow dr = personTable.Select("StationEventPersonID=" + firelinkInfo.CoorindatorID)[0];
                        this.txtFirelinkCoordinator.Text = dr["StaffName"].ToString();
                    }

                    //----------------------------End Setting----------------------------------------

                    //RestoreCHUBB
                    if (personTable.Select("StationEventPersonID=" + firelinkInfo.RestoreCHUBBID.Value).Length > 0)
                    {
                        DataRow dr = personTable.Select("StationEventPersonID=" + firelinkInfo.RestoreCHUBBID.Value)[0];
                        this.txtRestoreCHUBB.Text = dr["StaffName"].ToString();
                    }
                    //-------------------------------------------------------------------------------

                    if (tempID < 0)//Create temp data.
                    {
                        string xmlContent = BLL.SOM.Event.FireProtection.CreateDataSetXml(this.LangCode, this.ParentEventID);
                        TempID = DAL.SOM.TempData.AddTempData(this.ODMUser.ID, this.ODMUser.Domain, xmlContent);
                    }

                    this.imgAssetLoanEventStatus.Attributes["title"] = this.GetEventStatusDesc(this.EventStatusID, this.LangCode);//add at 2008-12-10
                    this.imgAssetLoanEventStatusNew.Attributes["title"] = this.GetEventStatusDesc(this.EventStatusID, this.LangCode);//add at 2008-12-10

                    SetRequestPersonTypeICO();//set request person type icon.

                    //add by gordon 20150804 U146.2
                    ShowEMOnCompletedStatus(stationEventInfo.EventStatusID);

                    //add by Tim 20160309 U57
                    this.rblStatus.Enabled = false;

                    #endregion
                }

                //------------Add at 2009-02-04---------------
                if (this.StationEventID < 1)
                {
                    this.chkRestoreNormal.Enabled = false;
                }
                //-----------End add at 2009-02-04 ------------

                //------Set station , Firelink, request by disable.--------
                if (this.StationEventID > 0)
                {
                    this.ddlStation.Enabled = false;
                    this.ddlFireLink.Enabled = false;

                    if (this.hdnStaffType.Value.Trim().Length > 0)
                    {
                        if (this.hdnStaffType.Value.Trim() != "4")
                        {
                            this.SetRequestReadOnly(true);
                        }
                    }
                }
                //----------------Set End------------------


                //--------------Set Handover check-----------

                if (this.chkHandoverNot.Checked)
                {
                    if (!this.ReadOnly && !this.HaveParent)
                    {
                        this.txtHandoverNote.Enabled = true;
                    }
                }
                else
                {
                    this.txtHandoverNote.Enabled = false;
                }

                HandoverNotCheckedChanged();

                //------------Set End---------------------

                #endregion

                //The status will not changed once the reroc is saved.
                if (this.StationEventID > 0)
                {
                    this.rblStatus.Enabled = false;
                }
            }

            //Add client onclick event at normal item.
            if (this.rblStatus.Items.FindByValue("1") != null)
            {
                this.rblStatus.Items.FindByValue("1").Attributes.Add("onclick", "ResortNormalCheck(this,'" + this.OtherEventUrl + "','" + this.GetMessage("SOM_FireZoneGroupIsolateByOtherEvent", this.LangCode) + "');");
            }

            if (this.ReadOnly)
            {
                SetReadOnly(true);
            }


            //----------------------Add at 2008-12-04---------------------

            if (this.CalledBy == 2)// if call by AR then can't check request by information. 
            {
                this.requestByEM.Visible = false;
                this.requestByNameEM.Visible = false;
                this.requestByDeptEM.Visible = false;

                //Issue U38: Add By Gordon 2015/05/28
                this.requeseByContactNumEM.Visible = false;
            }

            //---------------------End add at 2008-12-04------------------

            ParameterSetting();
            FunctionItemSetting();

            /* add by jack 20150527 for U41 */
            if (this.rblStatus.SelectedValue == "1")
            {
                this.chkRestoreNormal.Enabled = false;
            }
            /********************************/
        }

        //Bind fire link.
        private void BindFireLink()
        {
            int stationID = 0;

            if (this.ddlStation.SelectedItem != null)
            {
                stationID = Convert.ToInt32(ddlStation.SelectedItem.Value);
            }

            DataTable dt = ODMS.DAL.SOM.CodeSetup.CDFireLink.GetFirelinkCode(this.LangCode, stationID);

            if (this.Action == 1)
            {
                DataRow[] obsoleteRows = dt.Select("FlagObsolete=1");

                foreach (DataRow dr in obsoleteRows)
                {
                    dt.Rows.Remove(dr);
                }

                dt.AcceptChanges();

                BindListControl(this.ddlFireLink, "FirelinkID", "FireLinkCode", dt, true, "-1");
            }
            else
            {
                BindListControl(this.ddlFireLink, "FirelinkID", "FireLinkCode", dt, false);
            }
        }

        //set highlight flag.
        private void SetHighlightFlag(int iFlag)
        {
            //update by benson 2015.08.27 u183.3 begin
            if (this.EventStatusID == 2)
            {
                this.imgAssetLoanEventHighLight.Src = "../../Images/SOM/HighLight_Normal.gif";
                this.imgAssetLoanEventHighLight.Attributes["title"] = this.GetLabel("SOM_HighLightNormal");
            }
            //update by benson 2015.08.27 u183.3 end
            else if (iFlag == 0)
            {
                this.imgAssetLoanEventHighLight.Src = "../../Images/SOM/HighLight_Normal.gif";
                this.imgAssetLoanEventHighLight.Attributes["title"] = this.GetLabel("SOM_HighLightNormal");
            }
            else if (iFlag == 1)
            {
                this.imgAssetLoanEventHighLight.Src = "../../Images/SOM/HighLight_Yellow.gif";
                this.imgAssetLoanEventHighLight.Attributes["title"] = this.GetLabel("SOM_HighLightYellow");
            }
            else //3
            {
                this.imgAssetLoanEventHighLight.Src = "../../Images/SOM/HighLight_Red.gif";
                this.imgAssetLoanEventHighLight.Attributes["title"] = this.GetLabel("SOM_HighLightRed");
            }
        }

        //Get event status description by eventstatusID and langCode.
        private string GetEventStatusDesc(int eventStatusID, string langCode)
        {
            DataTable dt = DAL.SOM.CodeSetup.CDEventStatus.GetEventStatusByID(langCode, eventStatusID);

            return dt.Rows.Count > 0 ? dt.Rows[0]["Description"].ToString() : "";
        }

        //Bind fire link status.
        private void BindFireLinkStatus()
        {
            BindListControl(this.rblStatus, "FireLinkStatusID", "FireLinkStatusCode", DAL.SOM.CodeSetup.CDFireLinkStatus.GetAllFireLinkStatus(this.LangCode), false);

            //Remove VRT if current version=BJL4.
            //if (this.Version == MTRC.ODMS.BLL.EnvVersion.BJL4 && rblStatus.Items.FindByValue("3") != null) //del by zengshunbo 2009-06-15 //Merge Stockholm&HK to BJL4-----
            if (DAL.CommonData.GetCharVal("MV_SOM_FirePortectionEntryVRT_Visible").ToUpper() == "N" && rblStatus.Items.FindByValue("3") != null) //Merge Stockholm&HK to BJL4-----
            {
                rblStatus.Items.Remove(rblStatus.Items.FindByValue("3"));
            }

            this.rblStatus.SelectedIndex = 0;
        }
        /// <summary>
        /// add by benson 2015-07-02  
        /// </summary>
        private void BindHandleBy()
        {
            //update by gordon 20160124 ISU04
            //BindListControl(this.ddlHandledby, "userID", "userName", DAL.SOM.CodeSetup.CDAssetType.getUserIDbyUserGroup(this.ODMUser.UserGroupID, Convert.ToInt16(LangCode)), true, "");
            BindListControl(this.ddlHandledby, "userID", "userName", DAL.SOM.CodeSetup.CDAssetType.getUserIDbyUserGroup(this.ODMUser.UserGroupID, Convert.ToInt16(LangCode),this.StationEventID), true, "");
        }
        //Bind station list.
        private void BindStation()
        {
            if (this.CalledBy == 1 && !this.HaveParent && DAL.Security.User.CanFunctionItemAccess("M140302_F2", this.ODMUser.UserProfileID, this.MenuID))
            {
                //update by gordon 20151020 U247
                //BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.StationID), false);
                BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.LocationID), false);
            }
            else
            {
                //update by gordon 20151020 U247
                //BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, true, Convert.ToInt16(LangCode), this.ODMUser.StationID), true);
                BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, true, Convert.ToInt16(LangCode), this.ODMUser.LocationID), true);
            }
        }

        //Data validate.
        private bool DataValidate()
        {
            bool bTemp = true;

            if (this.txtIsolationDuration.Text.Trim() != string.Empty)
            {
                //SHould use regx to judge the input data format whether or not match up the right format, #.#, 1 bit decimal
                string matchStr = @"^[0-9]+(.[0-9]{1})?$";
                System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex(matchStr);
                if (!regx.IsMatch(txtIsolationDuration.Text.Trim()))
                {
                    this.PAlert(this.GetMessage("SOM_EstimateCompletionDateTimeHrsCheck"), 0, this.txtIsolationDuration);
                }
            }

            return bTemp;
        }

        /// <summary>
        /// set request person type ico.
        /// </summary>
        private void SetRequestPersonTypeICO()
        {
            if (this.hdnStaffType.Value.ToString().Trim().Length > 0)
            {
                if (this.hdnStaffType.Value.ToString().Trim() == "1")
                {
                    this.imgRequest.ImageUrl = "../../Images/SOM/StaffType_Staff.gif";

                    this.imgRequest.ToolTip = hdnImgStaffTypeTooltip1.Value;
                }
                else if (this.hdnStaffType.Value.ToString().Trim() == "2")
                {
                    this.imgRequest.ToolTip = hdnImgStaffTypeTooltip2.Value;

                    this.imgRequest.ImageUrl = "../../Images/SOM/StaffType_CQAContractor.gif";
                }
                else if (this.hdnStaffType.Value.ToString().Trim() == "3")
                {
                    this.imgRequest.ToolTip = hdnImgStaffTypeTooltip3.Value;

                    this.imgRequest.ImageUrl = "../../Images/SOM/StaffType_StationContractor.gif";
                }
                else //4
                {
                    this.imgRequest.ToolTip = hdnImgStaffTypeTooltip4.Value;

                    this.imgRequest.ImageUrl = "../../Images/SOM/StaffType_AddHoc.gif";
                }

                //this.imgStaffType.Attributes["title"] = imgStaffTypeTooltip;
            }
        }

        //Function item setting.
        private void FunctionItemSetting()
        {
            if (DAL.Security.User.CanFunctionItemAccess("M140302_F1", this.ODMUser.UserProfileID, this.MenuID) && this.StationEventID < 1)//See all stations.
            {
                this.ddlStation.Enabled = true;
                this.ddlFireLink.Enabled = true;
            }
            //add by gordon 20151031 u261
            else if (DAL.Security.User.CanFunctionItemAccess("M140302_F2", this.ODMUser.UserProfileID, this.MenuID) && this.StationEventID < 1)//Can access other stations.
            {
                this.ddlStation.Enabled = true;
                this.ddlFireLink.Enabled = true;
            }
            //else if (DAL.Security.User.CanFunctionItemAccess("M140102_F6", this.ODMUser.UserProfileID, this.MenuID) && this.StationEventID < 1)
            //{               
            //    this.ddlFireLink.Enabled = true;
            //}
            else
            {
                this.ddlStation.Enabled = false;
            }

            //set can amend time.
            //if (DAL.Security.User.CanFunctionItemAccess("M140302_F4", this.ODMUser.UserProfileID, this.MenuID))
            if (DAL.Security.User.CanFunctionItemAccess("M140302_F4", this.ODMUser.UserProfileID, this.MenuID) || this.CalledBy == 2)//Issue U15:[|| this.CalledBy == 2 ]Update By Gordon 2015/05/25
            {
                this.CanAmendTime = true;
            }
        }

        //ParameterSetting.
        private void ParameterSetting()
        {
            //Issue U15:Update BY Gordon 2015/05/25
            //if (MTRC.ODMS.DAL.CommonData.GetCharVal("SOM_FireLink_CanAmendEventTime").Trim() == "Y" && this.CalledBy == 1)
            if (MTRC.ODMS.DAL.CommonData.GetCharVal("SOM_FireLink_CanAmendEventTime").Trim() == "Y")
            {
                this.btnAmendEventTime.Visible = true;
            }
            else
            {
                this.btnAmendEventTime.Visible = false;
            }
        }

        //Set request by informat is readonly.
        private void SetRequestReadOnly(bool readOnly)
        {
            if (readOnly)
            {
                //this.txtRequestByContactNumber.Enabled = false;
                this.txtRequestByDept.Enabled = false;
                //this.txtRequestByID.Enabled = false;
                this.txtRequestByName.Enabled = false;
                this.txtRequestByOU.Enabled = false;
            }
            else
            {
                //this.txtRequestByContactNumber.Enabled = true;
                this.txtRequestByDept.Enabled = true;
                //this.txtRequestByID.Enabled = true;
                this.txtRequestByName.Enabled = true;
                //this.txtRequestByOU.Enabled = true;
            }
        }

        //Convert datatable to fire zone group list.
        private ArrayList DataTableConvertToFireZoneGroup(DataTable dt)
        {
            ArrayList fireZoneGroups = new ArrayList();
            Hashtable hashStatus = GetGroupStatusData();

            foreach (DataRow dr in dt.Rows)
            {
                Model.SOM.Event.StationEventFireZoneGroupInfo tempZoneGroupInfo = new MTRC.ODMS.Model.SOM.Event.StationEventFireZoneGroupInfo();
                int tempInt = 0;
                int.TryParse(dr["StationEventFireZoneGroupID"].ToString(), out tempInt);
                tempZoneGroupInfo.StationEventFireZoneGroupID = tempInt;

                tempZoneGroupInfo.StationEventFirelInkID = this.ddlFireLink.SelectedItem != null ? Convert.ToInt32(ddlFireLink.SelectedItem.Value) : 0;//Convert.ToInt32(dr["StationEventFirelInkID"].ToString());
                tempZoneGroupInfo.FireZoneGrpID = Convert.ToInt32(dr["FireZoneGrpID"].ToString());
                tempZoneGroupInfo.LastUpdUser = this.ODMUser.ID;
                tempZoneGroupInfo.ActingasUser = this.ODMUser.ID;

                if (this.chkIsolateAll.Checked)//Isolate all
                {
                    tempZoneGroupInfo.FireZoneGrpIDStatusID = 2;
                }
                else if (this.chkRestoreAll.Checked)//Restore all
                {
                    if (Convert.ToInt32(dr["FireZoneGrpIDStatusID"].ToString()) != 1)
                    {
                        tempZoneGroupInfo.FireZoneGrpIDStatusID = 3;
                    }
                    else
                    {
                        tempZoneGroupInfo.FireZoneGrpIDStatusID = 1;
                    }
                }
                //else if (hashStatus[dr["StationEventFireZoneGroupID"].ToString()] != null)
                else if (hashStatus[dr["FireZoneGrpID"].ToString()] != null)
                {
                    if (Convert.ToInt32(hashStatus[dr["FireZoneGrpID"].ToString()]) == 1)
                    {
                        tempZoneGroupInfo.FireZoneGrpIDStatusID = 1;
                    }
                    else if (Convert.ToInt32(hashStatus[dr["FireZoneGrpID"].ToString()]) == 2)
                    {
                        tempZoneGroupInfo.FireZoneGrpIDStatusID = 2;
                    }
                    else if (Convert.ToInt32(hashStatus[dr["FireZoneGrpID"].ToString()]) == 3)
                    {
                        tempZoneGroupInfo.FireZoneGrpIDStatusID = 3;
                    }
                }
                else
                {
                    tempZoneGroupInfo.FireZoneGrpIDStatusID = Convert.ToInt32(dr["FireZoneGrpIDStatusID"].ToString());
                }

                tempZoneGroupInfo.LastUpdTime = this.ConvertToDateTime((dr["LastUpdTime"].ToString()));
                tempZoneGroupInfo.LastUpdUser = Convert.ToInt32(dr["LastUpdUser"].ToString());
                tempZoneGroupInfo.ActingasUser = Convert.ToInt32(dr["ActingasUser"].ToString());

                fireZoneGroups.Add(tempZoneGroupInfo);
            }

            return fireZoneGroups;
        }

        /// <summary>
        /// Set some controls value when from AR.
        /// </summary>
        public void SetControlValue()
        {
            if (Request.QueryString["StatffID"] != null)
            {
                //this.txtRequestByID.Text = Request.QueryString["StatffID"].ToString();
                this.txtRequestByID.Text = this.Server.UrlDecode(Request.QueryString["StatffID"]).ToString();

            }

            if (Request.QueryString["txtIsolationDateTime"] != null)
            {
                //this.txtIsolationDateTime.Text = Request.QueryString["txtIsolationDateTime"].ToString();
                this.txtIsolationDateTime.Text = this.Server.UrlDecode(Request.QueryString["txtIsolationDateTime"]).ToString();
            }

            if (Request.QueryString["imgRequesSrc"] != null)
            {
                //this.imgRequest.ImageUrl = Request.QueryString["imgRequesSrc"].ToString();
                this.imgRequest.ImageUrl = this.Server.UrlDecode(Request.QueryString["imgRequesSrc"]).ToString();
            }

            if (Request.QueryString["txtRequestByName"] != null)
            {
                //this.txtRequestByName.Text = Request.QueryString["txtRequestByName"].ToString();
                this.txtRequestByName.Text = this.Server.UrlDecode(Request.QueryString["txtRequestByName"]).ToString();
            }

            if (Request.QueryString["txtRequestByDept"] != null)
            {
                //update by gordon 20150710 decode from js escape value | orgunit instead of depart
                //this.txtRequestByDept.Text = Request.QueryString["txtRequestByDept"].ToString();
                //this.txtRequestByDept.Text = System.Web.HttpUtility.UrlDecode(Request.QueryString["txtRequestByDept"].ToString());
                this.txtRequestByDept.Text = this.Server.UrlDecode(Request.QueryString["txtRequestByDept"]).ToString();
            }

            if (Request.QueryString["txtRequestByOU"] != null)
            {
                //this.txtRequestByOU.Text = Request.QueryString["txtRequestByOU"].ToString();
                this.txtRequestByOU.Text = this.Server.UrlDecode(Request.QueryString["txtRequestByOU"]).ToString();
            }

            if (Request.QueryString["txtRequestByContactNumber"] != null)
            {
                //this.txtRequestByContactNumber.Text = Request.QueryString["txtRequestByContactNumber"].ToString();
                this.txtRequestByContactNumber.Text = this.Server.UrlDecode(Request.QueryString["txtRequestByContactNumber"]).ToString();
            }

            if (Request.QueryString["txtIsolationDuration"] != null)
            {
                //this.txtIsolationDuration.Text = Request.QueryString["txtIsolationDuration"].ToString();
                this.txtIsolationDuration.Text = this.Server.UrlDecode(Request.QueryString["txtIsolationDuration"]).ToString();
            }

            if (Request.QueryString["lblEstimatedIsolationDate"] != null)
            {
                //this.lblEstimatedIsolationDate.Text = Request.QueryString["lblEstimatedIsolationDate"].ToString();
                this.lblEstimatedIsolationDate.Text = this.Server.UrlDecode(Request.QueryString["lblEstimatedIsolationDate"]).ToString();
            }

            if (Request.QueryString["chkHandoverCheck"] != null)
            {
                //if (Request.QueryString["chkHandoverCheck"].ToString().Trim().ToUpper() == "TRUE")
                if (this.Server.UrlDecode(Request.QueryString["chkHandoverCheck"]).ToString().Trim().ToUpper() == "TRUE")
                {
                    this.chkHandoverNot.Checked = true;
                }
            }

            if (Request.QueryString["txtHandoverNote"] != null)
            {
                //this.txtHandoverNote.Text = Request.QueryString["txtHandoverNote"].ToString();
                this.txtHandoverNote.Text = this.Server.UrlDecode(Request.QueryString["txtHandoverNote"]).ToString();
            }

            if (Request.QueryString["hdnInitDateTime"] != null)
            {
                //this.hdnInitDateTime.Value = Request.QueryString["hdnInitDateTime"].ToString();
                this.hdnInitDateTime.Value = this.Server.UrlDecode(Request.QueryString["hdnInitDateTime"]).ToString();
            }

            if (Request.QueryString["hdnRequestStaffOrExtPartyID"] != null)
            {
                //this.hdnRequestStaffOrExtPartyID.Value = Request.QueryString["hdnRequestStaffOrExtPartyID"].ToString();
                this.hdnRequestStaffOrExtPartyID.Value = this.Server.UrlDecode(Request.QueryString["hdnRequestStaffOrExtPartyID"]).ToString();
            }
        }

        //Get Event status Icon path by status id.
        private string GetEventStatusIconPath(int statusID)//Add at 2008-11-14.
        {
            string iconPath = "";
            if (statusID == 1)
            {
                iconPath = "../../Images/SOM/EventStatus_OS.gif";
            }
            else if (statusID == 2)
            {
                iconPath = "../../Images/SOM/EventStatus_COM.gif";
            }
            else //3 
            {
                iconPath = "../../Images/SOM/EventStatus_Void.gif";
            }

            return iconPath;
        }

        //Bind 
        private void BindReason()
        {
            BindListControl(this.ddlReason, "IsolateReasonID", "IsolateReasonCode", DAL.SOM.CodeSetup.CDIsolateReason.GetAllIsolateReason(this.LangCode), true, "-1");
        }

        //Get changed fire zone group used for temp data.
        private DataTable GetFireZoneGroup()
        {
            DataTable dt = DAL.SOM.Event.StationEventFireZoneGroupDa.GetFireZoneGroupByFirelinkID(Convert.ToInt32(this.ddlFireLink.SelectedValue));
            //DataTable dt = GetFireZoneGroupStatusTable();

            dt.Rows.Clear();
            dt.AcceptChanges();

            DataTable dtSourceTable = GetFireZoneGroupStatusTable();
            Hashtable hashStatus = GetGroupStatusData();
            int rowNo = 0;

            foreach (DataRow dr in dtSourceTable.Rows)
            {
                rowNo--;
                DataRow newRow = dt.NewRow();

                //newRow["StationEventFireZoneGroupID"] = Convert.ToInt32(ViewState["StationEventID"].ToString()) != 0 ? Convert.ToInt32(dr["StationEventFireZoneGroupID"]) : rowNo; //Modify at 2009-02-09
                newRow["StationEventFireZoneGroupID"] = this.StationEventID != 0 ? Convert.ToInt32(dr["StationEventFireZoneGroupID"]) : rowNo;


                if (dtSourceTable.Columns.Contains("StationEventFirelInkID"))
                {
                    newRow["StationEventFirelInkID"] = this.StationEventID > 0 ? Convert.ToInt32(dr["StationEventFirelInkID"].ToString()) : -1;
                }
                else
                {
                    newRow["StationEventFirelInkID"] = -1;
                }

                newRow["FireZoneGrpID"] = Convert.ToInt32(dr["FireZoneGrpID"]);
                newRow["FireZoneGrpIDStatusID"] = hashStatus.ContainsKey(dr["FireZoneGrpID"].ToString()) ? Convert.ToInt32(hashStatus[dr["FireZoneGrpID"].ToString()]) : Convert.ToInt32(dr["FireZoneGrpIDStatusID"]);
                newRow["LastUpdUser"] = this.ODMUser.ID;
                newRow["LastUpdTime"] = DAL.COM.Util.GetCurrentSystemTime().ToString("yyyy-MM-dd HH:mm", System.Globalization.DateTimeFormatInfo.InvariantInfo);

                //newRow["ActingasUser"] = Convert.ToInt32(ViewState["StationEventID"].ToString()) != 0 ? dr["ActingasUser"] : this.ODMUser.ID;//Modify at 2009-02-09
                newRow["ActingasUser"] = this.StationEventID != 0 ? dr["ActingasUser"] : this.ODMUser.ID;

                if (dt.Select("FireZoneGrpID=" + Convert.ToInt32(dr["FireZoneGrpID"]) + "").Length < 1) //remove the some rows.
                {
                    dt.Rows.Add(newRow);
                }
            }

            return dt;
        }

        /// <summary>
        /// GetEventTimeAndUserGroupID
        /// add by gordon 20150818 U125.1
        /// </summary>
        /// <returns></returns>
        private DataTable GetEventTimeAndUserGroupID()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("StationEventID", typeof(int)));
            dt.Columns.Add(new DataColumn("EventTime", typeof(string)));
            dt.Columns.Add(new DataColumn("UserGroupID", typeof(int)));

            DataRow dr = dt.NewRow();
            dr["StationEventID"] = this.StationEventID;
            //Update by Jack 20151121 U263 format datetime for EventTime such as '21/11/2015 11:12:10'
            //dr["EventTime"] = this.FormatDateTime(this.ConvertToDateTime(this.txtIsolationDateTime.Text));
            dr["EventTime"] =APJ.Util.Utility.FormatDateTime(this.ConvertToDateTime(this.txtIsolationDateTime.Text), true, true);
            //End Update by Jack 20151121 U263 format datetime for EventTime such as '21/11/2015 11:12:10'
            dr["UserGroupID"] = this.ODMUser.UserGroupID;
            //dr["UserGroupID"] = null;

            dt.Rows.Add(dr);

            return dt;
        }

        //Get station event used for temp data.
        private DataTable GetStationEvent()
        {
            DataTable dt = DAL.SOM.Event.StationEventDa.GetStationEventByParentID(0, 3);
            dt.Rows.Clear();
            dt.AcceptChanges();

            DataRow dr = dt.NewRow();
            dr["StationEventID"] = Convert.ToInt32(this.StationEventID);//
            dr["LocationID"] = this.ddlStation.SelectedValue;
            dr["EventTypeID"] = 3;
            //dr["EventNo"] = ViewState["EventNo"] != null ? ViewState["EventNo"].ToString() : "";
            dr["EventNo"] = ViewState["EventNo"] != null ? ViewState["EventNo"].ToString() : this.lblParentEventNo.Text;// Modify at 2008-12-10

            dr["EventTime"] = this.ConvertToDateTime(this.txtIsolationDateTime.Text);

            //dr["StationEventSignID"]="";
            dr["EstimatedWrkHour"] = float.Parse(txtIsolationDuration.Text);
            if (this.lblCompleteRestoreTime.Text.Trim().Length > 0)
            {
                dr["EventCompleteTime"] = this.ConvertToDateTime(this.lblCompleteRestoreTime.Text.Trim());
            }
            else
            {
                dr["EventCompleteTime"] = System.DBNull.Value;
            }

            //dr["StationEventCompleteSignID"] = "";
            //dr["AmendReason"]=""; 
            dr["Description"] = this.txtRemarks.Text;
            dr["Remark"] = this.txtRemarks.Text;
            dr["ParentStationEventID"] = Convert.ToInt32(this.ParentEventID);
            dr["StationEventPersonID"] = Convert.ToInt32(ViewState["RequestPersonID"]);
            //dr["DisplayOrder"]="";
            dr["EventStatusID"] = ViewState["EventStatusID"] != null ? Convert.ToInt32(ViewState["EventStatusID"]) : 0;
            dr["FlagHandover"] = this.chkHandoverNot.Checked;
            dr["HandoverNote"] = this.txtHandoverNote.Text;
            if (Convert.ToInt32(this.StationEventID) < 0)
            {
                dr["HighLight"] = 0;
            }
            else
            {
                dr["HighLight"] = System.DBNull.Value;
            }

            if (Convert.ToInt32(this.StationEventID) < 0)
            {
                dr["CreateUser"] = this.ODMUser.ID;
            }
            else
            {
                dr["CreateUser"] = System.DBNull.Value;
            }

            dr["CreateTime"] = DAL.COM.Util.GetCurrentSystemTime();
            //dr["FlagObsolete"]="";
            //dr["RequirePasswordUserID"]="";
            //dr["RequirePasswordStaffInfoID"]="";
            dr["LastUpdUser"] = this.ODMUser.ID;
            dr["LastUpdTime"] = DAL.COM.Util.GetCurrentSystemTime();
            if (Convert.ToInt32(this.StationEventID) < 0)
            {
                dr["ActingasUser"] = this.ODMUser.ID;
            }
            else
            {
                dr["ActingasUser"] = System.DBNull.Value;
            }

            dt.Rows.Add(dr);

            return dt;
        }

        //Get station event used for temp data.
        private DataTable GetStationEventFirelink()
        {
            DataTable dt = DAL.SOM.Event.StationEventFirelinkDa.GetEventFirelinkByEventID(0);
            dt.Rows.Clear();
            dt.AcceptChanges();
            DataRow dr = dt.NewRow();

            dr["StationEventFirelInkID"] = this.StationEventFirelinkID;
            dr["StationEventID"] = Convert.ToInt32(this.StationEventID);
            dr["FirelinkID"] = this.ddlFireLink.SelectedValue;
            dr["FirelinkStatusID"] = this.rblStatus.SelectedValue;
            dr["FlagRestore"] = this.chkRestoreNormal.Checked;
            if (this.lblCompleteRestoreTime.Text.Trim().Length > 0)
            {
                dr["RestoreTime"] = this.ConvertToDateTime(this.lblCompleteRestoreTime.Text.Trim());
            }
            else
            {
                dr["RestoreTime"] = System.DBNull.Value;
            }

            dr["IsolateReasonID"] = this.ddlReason.SelectedValue;
            dr["CoorindatorID"] = Convert.ToInt32(ViewState["CoordinatorPersonID"]);
            //update by gordon 20150708 Req11.3
            //dr["ResponsiblePersonID"] = Convert.ToInt32(ViewState["ReponsiblePersonID"]);
            dr["ResponsiblePersonID"] = ddlHandledby.SelectedValue;
            //Add by gordon 20150707 U95
            dr["RestoreCHUBBID"] = Convert.ToInt32(ViewState["RestoreCHUBB"]);
            dr["RestoreHandleByID"] = string.IsNullOrEmpty(this.ddlRestoreHandleBy.SelectedValue) ? "0" : this.ddlRestoreHandleBy.SelectedValue;
            //--------------------------
            if (Convert.ToInt32(this.StationEventID) < 0)
            {
                dr["CreateUser"] = this.ODMUser.ID;
            }
            else
            {
                dr["CreateUser"] = System.DBNull.Value;
            }

            dr["CreateTime"] = DAL.COM.Util.GetCurrentSystemTime();
            dr["LastUpdUser"] = this.ODMUser.ID;
            dr["LastUpdTime"] = DAL.COM.Util.GetCurrentSystemTime();
            if (Convert.ToInt32(this.StationEventID) < 0)
            {
                dr["ActingasUser"] = this.ODMUser.ID;
            }
            else
            {
                dr["ActingasUser"] = System.DBNull.Value;
            }

            dt.Rows.Add(dr);

            return dt;
        }

        //Get station event person for temp data.
        private DataTable GetStationEventPerson()
        {
            DataTable dt = DAL.SOM.Event.StationEventPersonDa.GetEventPersonListByEventID(0);
            dt.Rows.Clear();
            dt.AcceptChanges();

            //------------Request by----------------
            DataRow requestRow = dt.NewRow();
            requestRow["StationEventPersonID"] = Convert.ToInt32(ViewState["RequestPersonID"]);
            requestRow["StationEventID"] = Convert.ToInt32(this.StationEventID);
            //requestRow["SequenceNo"] = "";
            requestRow["EventPersonTypeID"] = this.hdnStaffType.Value.Trim().Length > 0 ? Convert.ToInt32(this.hdnStaffType.Value.Trim()) : 4;//default:4
            requestRow["StaffOrExtPartyID"] = this.hdnRequestStaffOrExtPartyID.Value.Trim().Length > 0 ? Convert.ToInt32(this.hdnRequestStaffOrExtPartyID.Value) : 0;
            requestRow["StaffID"] = this.txtRequestByID.Text.Trim();
            requestRow["StaffName"] = this.txtRequestByName.Text;
            requestRow["Tel"] = this.txtRequestByContactNumber.Text;
            requestRow["Company"] = this.txtRequestByDept.Text;
            //requestRow["ReqQual"] = 
            //requestRow["FlagObsolete"] = "";
            requestRow["LastUpdUser"] = this.ODMUser.ID;
            requestRow["LastUpdTime"] = DAL.COM.Util.GetCurrentSystemTime();
            requestRow["ExtPartyStaffSnapShotID"] = this.hdnExtPartyStaffSnapShotID.Value.Trim().Length > 0 ? Convert.ToInt32(this.hdnExtPartyStaffSnapShotID.Value.Trim()) : 0;
            if (Convert.ToInt32(ViewState["StationEventID"].ToString()) < 0)
            {
                requestRow["ActingasUser"] = this.ODMUser.ID;
            }
            else
            {
                requestRow["ActingasUser"] = System.DBNull.Value;
            }

            dt.Rows.Add(requestRow);


            //delete by gordon 20150708 Req11.3
            //------------Reponsible by----------------
            //DataRow responsibleRow = dt.NewRow();
            //responsibleRow["StationEventPersonID"] = Convert.ToInt32(ViewState["ReponsiblePersonID"]);
            //responsibleRow["StationEventID"] = Convert.ToInt32(this.StationEventID);
            ////responsibleRow["SequenceNo"] = "";
            //responsibleRow["EventPersonTypeID"] = this.hdnResponsibleByType.Value.Trim().Length > 0 ? Convert.ToInt32(this.hdnResponsibleByType.Value) : 0;
            ////--------huangyao 20081017-------
            ////responsibleRow["StaffOrExtPartyID"] = this.hdnResponsibleStaffOrExtPartyID.Value;
            //if (this.hdnResponsibleStaffOrExtPartyID.Value.Trim() != "")
            //{
            //    responsibleRow["StaffOrExtPartyID"] = int.Parse(this.hdnResponsibleStaffOrExtPartyID.Value.Trim());
            //}
            ////-----end---huangyao 20081017-------
            //responsibleRow["StaffID"] = this.hdnResponsibleByID.Value;
            //responsibleRow["StaffName"] = this.ddlHandledby.SelectedItem.Text;
            ////responsibleRow["Tel"] = "";
            ////responsibleRow["Company"] = "";
            ////responsibleRow["ReqQual"] = "";
            ////responsibleRow["FlagObsolete"] = "";
            //responsibleRow["LastUpdUser"] = this.ODMUser.ID;
            //responsibleRow["LastUpdTime"] = DAL.COM.Util.GetCurrentSystemTime();
            //responsibleRow["ExtPartyStaffSnapShotID"] = 0; // Hard code ExtPartyStaffSnapShotID.
            //if (Convert.ToInt32(this.StationEventID) < 0)
            //{
            //    responsibleRow["ActingasUser"] = this.ODMUser.ID;
            //}
            //else
            //{
            //    responsibleRow["ActingasUser"] = System.DBNull.Value;
            //}
            //dt.Rows.Add(responsibleRow);

            //------------Coordinator by----------------
            DataRow coordinatorRow = dt.NewRow();
            coordinatorRow["StationEventPersonID"] = ViewState["CoordinatorPersonID"].ToString().Length > 0 ? Convert.ToInt32(ViewState["CoordinatorPersonID"]) : -1;
            coordinatorRow["StationEventID"] = Convert.ToInt32(this.StationEventID);
            //coordinatorRow["SequenceNo"] = "";
            coordinatorRow["EventPersonTypeID"] = 4;//hard code 4.
            //coordinatorRow["StaffOrExtPartyID"] = "";
            //coordinatorRow["StaffID"] = "";
            coordinatorRow["StaffName"] = this.txtFirelinkCoordinator.Text;
            //coordinatorRow["Tel"] = "";
            //coordinatorRow["Company"] = "";
            //coordinatorRow["ReqQual"] = "";
            //coordinatorRow["FlagObsolete"] = "";
            coordinatorRow["LastUpdUser"] = this.ODMUser.ID;
            coordinatorRow["LastUpdTime"] = DAL.COM.Util.GetCurrentSystemTime();
            coordinatorRow["ExtPartyStaffSnapShotID"] = 0;// Hard code ExtPartyStaffSnapShotID.
            if (Convert.ToInt32(this.StationEventID) < 0)
            {
                coordinatorRow["ActingasUser"] = this.ODMUser.ID;
            }
            else
            {
                coordinatorRow["ActingasUser"] = System.DBNull.Value;
            }
            dt.Rows.Add(coordinatorRow);
            //------------RestoreCHUBB-------------------- Add by gordon 20150707 U95
            DataRow restoreCHUBBRow = dt.NewRow();
            restoreCHUBBRow["StationEventPersonID"] = ViewState["RestoreCHUBB"].ToString().Length > 0 ? Convert.ToInt32(ViewState["RestoreCHUBB"]) : -1;
            restoreCHUBBRow["StationEventID"] = Convert.ToInt32(this.StationEventID);
            restoreCHUBBRow["EventPersonTypeID"] = 4;
            restoreCHUBBRow["StaffName"] = this.txtRestoreCHUBB.Text;
            restoreCHUBBRow["LastUpdUser"] = this.ODMUser.ID;
            restoreCHUBBRow["LastUpdTime"] = DAL.COM.Util.GetCurrentSystemTime();
            restoreCHUBBRow["ExtPartyStaffSnapShotID"] = 0;
            if (Convert.ToInt32(this.StationEventID) < 0)
            {
                restoreCHUBBRow["ActingasUser"] = this.ODMUser.ID;
            }
            else
            {
                restoreCHUBBRow["ActingasUser"] = System.DBNull.Value;
            }
            dt.Rows.Add(restoreCHUBBRow);

            return dt;
        }

        //Get station event amend time for temp data.
        private DataTable GetStationEventAmendTime()
        {
            DataTable dt = DAL.SOM.Event.StationEventAmendTimeDa.GetAllStaEventAmdTimeByStaEventID(this.LangCode, 1, 0);
            dt.Rows.Clear();
            dt.AcceptChanges();

            DataColumn isAmended = new DataColumn("IsAmended", Type.GetType("System.Boolean"));
            dt.Columns.Add(isAmended);

            //Add by Gordon 2015/05/25
            int initATID, drATID;
            GetStationEventAmendTimeIDS(out initATID, out drATID);

            DataRow initRow = dt.NewRow();
            //initRow["StationEventAmendTimeID"] = -1;
            initRow["StationEventAmendTimeID"] = initATID;//Issue U15:Update by gordon 2015/05/25
            initRow["StationEventID"] = Convert.ToInt32(this.StationEventID);
            initRow["TimeType"] = 1;//hard code
            //initRow["SequenceNo"] = "";
            //Add by jack 20151223 U291 The amendment history on isolation time is incorrect.
            //initRow["OriginalEventTime"] = this.ConvertToDateTime(this.hdnInitDateTime.Value);
            if (Session["AR_FireInitDateTime"]!=null)
            {
                initRow["OriginalEventTime"] = this.ConvertToDateTime(Session["AR_FireInitDateTime"].ToString());
            }
            //End Add by jack 20151223 U291 The amendment history on isolation time is incorrect.
            initRow["Reason"] = this.hdnDateTimeReason.Value;
            initRow["IsAmended"] = false;
            dt.Rows.Add(initRow);

            DataRow dr = dt.NewRow();
            //dr["StationEventAmendTimeID"] = -2;
            dr["StationEventAmendTimeID"] = drATID;//Issue U15:Update by gordon 2015/05/25
            dr["StationEventID"] = Convert.ToInt32(this.StationEventID);
            dr["TimeType"] = 1;//hard code
            //dr["SequenceNo"] = "";
            dr["OriginalEventTime"] = this.ConvertToDateTime(this.txtIsolationDateTime.Text);
            dr["Reason"] = this.hdnDateTimeReason.Value;
            //Issue U15:Update by gordon 2015/05/25
            //Add by tim 2015/12/16 U291 for AmentTime remove the second to compare
            // if (this.ConvertToDateTime(this.hdnInitDateTime.Value) == this.ConvertToDateTime(this.txtIsolationDateTime.Text))
            //if (this.ConvertToDateTime(this.hdnInitDateTime.Value).GetDateTimeFormats('g')[0].ToString() == this.ConvertToDateTime(this.txtIsolationDateTime.Text).GetDateTimeFormats('g')[0].ToString())
            if (this.ConvertToDateTime(Session["AR_FireInitDateTime"].ToString()).GetDateTimeFormats('g')[0].ToString() == this.ConvertToDateTime(this.txtIsolationDateTime.Text).GetDateTimeFormats('g')[0].ToString()) //Add by jack 20151223 U291 The amendment history on isolation time is incorrect.
                dr["IsAmended"] = false;
            else
                dr["IsAmended"] = true;
            dt.Rows.Add(dr);

            return dt;
        }

        /// <summary>
        /// GetStationEventAmendTimeIDS Issue U15: Add By Gordon 2015/05/25
        /// </summary>
        /// <param name="initATID">org</param>
        /// <param name="drATID">new</param>
        private void GetStationEventAmendTimeIDS(out int initATID, out int drATID)
        {
            DataTable dt = DAL.SOM.Event.StationEventAmendTimeDa.GetAllStaEventAmdTimeByStaEventID(this.LangCode, 1, this.StationEventID);
            if (dt.Rows.Count > 0)
            {
                DataView dv = dt.DefaultView;
                dv.Sort = "SequenceNo";
                DataTable newDt = dv.ToTable();
                initATID = Convert.ToInt32(newDt.Rows[0]["StationEventAmendTimeID"]);
                drATID = Convert.ToInt32(newDt.Rows[newDt.Rows.Count - 1]["StationEventAmendTimeID"]);
            }
            else
            {
                initATID = -1;
                drATID = -2;
            }
        }

        //Set read only.
        public void SetReadOnly(bool readOnly)
        {
            if (readOnly)
            {
                //this.chkHandoverNot

                this.txtIsolationDuration.Enabled = false;

                this.txtRequestByContactNumber.Enabled = false;
                this.txtRequestByDept.Enabled = false;
                this.txtRequestByID.Enabled = false;
                this.txtRequestByName.Enabled = false;
                this.txtRequestByOU.Enabled = false;
                this.ddlHandledby.Enabled = false;

                //Update by Jack 20150520 for U16
                //this.chkRestoreNormal.Enabled = false;
                //Update By Gordon 20150704 U16 - Use Function Item to Control whether user can resume a fire link even if the contractor has not completed the task or departed the station
                if (this.CalledBy == 2 && (!chkRestoreNormal.Checked))
                {
                    this.chkRestoreNormal.Enabled = DAL.Security.User.CanFunctionItemAccess("M140102_F7", this.ODMUser.UserProfileID, this.MenuID);
                }
                else
                    this.chkRestoreNormal.Enabled = false;
                ////////////////////////////////////////

                //this.btnAmendEventTime.Enabled = false;
                this.btnSelectRequest.Enabled = false;
                this.ddlFireLink.Enabled = false;
                this.ddlStation.Enabled = false;
                this.rblStatus.Enabled = false;


                if (this.ReadOnly)
                {
                    this.chkHandoverNot.Enabled = false;
                    this.txtHandoverNote.Enabled = false;

                    //this.imgSelectResponsible.Enabled = false;
                    //this.imgSelectResponsible.Visible = false;//add at 2008-11-14
                    this.btnSelectRequest.Visible = false;//add at 2008-11-14

                    this.ddlReason.Enabled = false;
                    this.txtRemarks.Enabled = false;

                    this.chkIsolateAll.Enabled = false;
                    this.chkRestoreAll.Enabled = false;

                    this.txtFirelinkCoordinator.Enabled = false;
                }

                //Can change fire zone group status and event status.
                if (this.CanChangeStatus)
                {
                    this.chkIsolateAll.Enabled = true;
                    this.chkRestoreAll.Enabled = true;
                    this.chkRestoreNormal.Enabled = true;
                }
            }
            else
            {
                //this.chkHandoverNot

                this.chkIsolateAll.Enabled = true;
                this.chkRestoreAll.Enabled = true;

                if (this.Action == 2)// Add at 2009-02-04
                {
                    this.chkRestoreNormal.Enabled = true;
                }

                this.txtFirelinkCoordinator.Enabled = true;

                //this.txtHandoverNote.Enabled = true; //Modify at 2009-02-06

                this.txtIsolationDuration.Enabled = true;
                this.txtRemarks.Enabled = true;
                this.txtRequestByContactNumber.Enabled = true;
                this.txtRequestByDept.Enabled = true;
                this.txtRequestByID.Enabled = true;
                this.txtRequestByName.Enabled = true;
                //this.txtRequestByOU.Enabled = true;
                //this.txtResponsibleBy.Enabled = true;
                this.ddlHandledby.Enabled = true;
                //this.btnAmendEventTime.Enabled = true;
                this.btnSelectRequest.Enabled = true;
                //this.imgSelectResponsible.Enabled = true;
                this.ddlReason.Enabled = true;
                this.rblStatus.Enabled = true;
                ///update by benson 2015.07.24 begin
                if (DAL.Security.User.CanFunctionItemAccess("M140302_F1", this.ODMUser.UserProfileID, this.MenuID) && this.StationEventID < 1)//See all stations.
                {
                    this.ddlStation.Enabled = true;
                    this.ddlFireLink.Enabled = true;
                }
                ///update by benson 2015.07.24 end
            }
        }

        //Restore all fire link and fire zone group.
        private void RestoreAll()
        {

        }

        //Isolate all fire link and fire zone group.
        private void IsolateAll()
        {

        }

        //Restore normal fire link.isNormal:Restore Normal checked on?
        private void RestoreNormal(bool isNormal)
        {
            if (isNormal)
            {
                this.lblRestoreTime.Text = this.FormatDateTime(DAL.COM.Util.GetCurrentSystemTime(), true);

                if (this.rblStatus.Items.FindByValue("1") != null)
                {
                    //set selected normal.
                    this.rblStatus.Items.FindByValue("1").Selected = true;
                }
            }
            else
            {
                this.lblRestoreTime.Text = "";
            }
        }

        /// <summary>
        /// Get all fire zone group status on changed.id:status,(26:2)
        /// </summary>
        /// <returns>Hashtable</returns>
        private Hashtable GetGroupStatusData()
        {
            //1:1,2:2,2:1,13:1,8:2,8:1,10:1,2:2,8:2,2:1,1:2,

            Hashtable hashTable = new Hashtable();
            string strData = this.txtFireZonePanelData.Value.Trim().Length > 1 ? this.txtFireZonePanelData.Value.Trim().Substring(0) : "";
            string[] dataArray = strData.Split(',');

            foreach (string item in dataArray)
            {
                if (item.Trim().Length < 1)
                {
                    break;
                }

                string itemKey = item.Split(':')[0];
                string itemValue = item.Split(':')[1];

                if (hashTable.ContainsKey(itemKey))
                {
                    hashTable[itemKey] = itemValue;
                }
                else
                {
                    hashTable.Add(itemKey, itemValue);
                }
            }

            return hashTable;
        }

        //Get zone group status by id.
        private string GetFireZoneGroupStatus(Hashtable htable, string strKey)
        {
            if (htable.ContainsKey(strKey))
            {
                return htable[strKey].ToString();
            }
            else
            {
                return "";
            }
        }

        //Check all controls value when saving.
        public bool SaveCheck(int flagCheckIsolete)
        {
            bool ch = true;

            //------------- add at:2008-11-21 by: HZX -------

            if (this.CalledBy == 1 && this.Action == 2)
            {
                string LastUpdBy = "";
                int result = MTRC.ODMS.DAL.SOM.Event.StationEventDa.LastUpdataTimeCheck(this.StationEventID, this.ConvertToDateTime(hdnStationEventLastUpdataTime.Value), this.LangCode, ref  LastUpdBy);
                if (result > 0)
                {
                    string strMsg = this.GetMessage("SOM_RecordAlreadyUpdataed");
                    //strMsg = strMsg.Replace("xxx", LastUpdBy);
                    strMsg = string.Format(strMsg, LastUpdBy);
                    Alert(strMsg);
                    ch = false;
                    return ch;
                }
            }

            //------------ end add at 2008-11-21 by:HZX -----

            if (this.ddlStation.SelectedItem == null)
            {
                PAlert("'" + this.lblStation.Text + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));
                ch = false;

                return ch;
            }

            if (this.rblStatus.SelectedItem == null)
            {
                PAlert("'" + this.lblStatus.Text + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));
                ch = false;

                return ch;
            }

            if (this.ddlFireLink.SelectedItem == null || this.ddlFireLink.SelectedItem.Text.Trim().Length < 1)
            {
                PAlert("'" + this.lblFireLink.Text + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));

                ch = false;
                return ch;
            }
            if (this.txtIsolationDateTime.Text.Trim().Length < 1)
            {
                PAlert("'" + this.lblIsolationTime.Text + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));

                ch = false;
                return ch;
            }

            /* add by jack 20150527 for U30 */
            if (this.lblFireLinkCoordinator.Text.Contains("<em>*</em>") && this.txtFirelinkCoordinator.Text.Trim().Length < 1)
            {
                PAlert("'" + this.lblFireLinkCoordinator.Text.Replace("<em>*</em>", "") + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));
                ch = false;
                return false;
            }
            /*******************************/

            //Add by gordon 20150707 U95
            if (this.txtRestoreCHUBB.Enabled && this.lblRestoreCHUBB.Text.Contains("<em>*</em>") && this.txtRestoreCHUBB.Text.Trim().Length < 1)
            {
                PAlert("'" + this.lblRestoreCHUBB.Text.Replace("<em>*</em>", "") + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));
                ch = false;
                return false;
            }

            //--------------------Add at 2008-12-02-----------------

            if (this.CalledBy == 1) // if call by AR then can't check request by information. add at 2008-12-04
            {
                if (this.txtRequestByID.Text.Trim().Length < 1)
                {
                    PAlert("'" + this.lblRequestByID.Text + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));

                    ch = false;
                    return ch;
                }

                if (this.txtRequestByName.Text.Trim().Length < 1)
                {
                    PAlert("'" + this.lblRequestByName.Text + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));

                    ch = false;
                    return ch;
                }

                if (this.txtRequestByDept.Text.Trim().Length < 1)
                {
                    PAlert("'" + this.lblRequestByDeptCompany.Text + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));

                    ch = false;
                    return ch;
                }

                //Issue U38: Add By Gordon 2015/05/28
                if (string.IsNullOrEmpty(this.txtRequestByContactNumber.Text.Trim()))
                {
                    PAlert("'" + this.lblRequestByContactNumber.Text + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));

                    ch = false;
                    return ch;
                }
            }

            //-------------------End add at 2008-12-04----------------

            //add by gordon 20150707 U95
            if (this.ddlRestoreHandleBy.Enabled)
            {
                if (this.ddlRestoreHandleBy.SelectedItem == null || this.ddlRestoreHandleBy.SelectedItem.Text.Trim().Length < 1)
                {
                    PAlert("'" + this.lblRestoreHandleBy.Text.Replace("<em>*</em>", "") + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));

                    ch = false;
                    return ch;
                }
            }

            if (this.ddlHandledby.SelectedItem == null || this.ddlHandledby.SelectedItem.Text.Trim().Length < 1)
            {
                PAlert("'" + this.lblHandledby.Text + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));

                ch = false;
                return ch;
            }

            if (this.ddlReason.SelectedItem == null || this.ddlReason.SelectedItem.Text.Trim().Length < 1)
            {
                PAlert("'" + this.lblReason.Text + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));

                ch = false;
                return ch;
            }

            if (this.chkHandoverNot.Checked && this.txtHandoverNote.Text.Trim().Length < 1 && this.CalledBy == 1)
            {
                PAlert("'" + this.lblHandoverNote.Text + "' " + GetMessage("SOM_NotIsEmpty", this.LangCode));

                ch = false;
                return ch;
            }

            if (this.Action == 1)
            {
                if (flagCheckIsolete > 0)
                {
                    if (!(this.txtFireZonePanelData.Value.IndexOf(":2") > 0 || this.rblStatus.SelectedValue != "1"))
                    {
                        PAlert(GetMessage("SOM_ExistOneZoneIslated", this.LangCode));

                        ch = false;//Must have 1 firelink or 1 firezone islated for a newly saved record.
                        return ch;
                    }
                }
            }

            return ch;
        }

        /// <summary>
        /// CheckOutStandingRecord
        /// </summary>
        public string CheckOutStandingRecord(string clientFireLinkId = "", string clientFireLinkCode = "")
        {
            //Issue U36: Add By Gordon 2015/05/28
            string retStr = string.Empty;
            //if (chkRestoreNormal.Checked)//Delete By Gordon 20150707 U36
            //{
            int fireLinkId = Convert.ToInt32(clientFireLinkId == "" ? ddlFireLink.SelectedValue : clientFireLinkId);
            if (BLL.SOM.Event.StationEventFirelink.CheckOutStandingRecord(fireLinkId))
            {
                //update by gordon 20150708 U36
                //retStr = GetMessage("SOM_ExistsOutStandingRecord", this.LangCode).Replace("[#FireLink]", ddlFireLink.SelectedItem.Text);
                retStr = GetMessage("SOM_ExistsOutStandingRecord", this.LangCode).Replace("[#FireLink]", clientFireLinkCode == "" ? ddlFireLink.SelectedItem.Text : clientFireLinkCode);
            }
            //}
            return retStr;
        }

        //if alled by AR then set some controls readonly.
        public void SetFromARReadOnly()
        {
            //Issue U15:Update By Gordon 2015/05/25
            //this.btnAmendEventTime.Enabled = false;
            this.btnAmendEventTime.Enabled = true;
            /* Issue 92: Update By Gordon 2015/05/11 */
            //this.txtIsolationDuration.Enabled = false;
            this.txtIsolationDuration.Enabled = true;
            /******************************************/
            this.txtRequestByID.Enabled = false;
            this.txtRequestByName.Enabled = false;
            this.txtRequestByDept.Enabled = false;
            this.txtRequestByOU.Enabled = false;
            this.txtRequestByContactNumber.Enabled = false;
            this.chkHandoverNot.Enabled = false;
            this.txtHandoverNote.Enabled = false;

            //this.ddlStation.Enabled = false;
        }

        //Set AllIsolateStationEventIDs
        private void RemoveSameStationEventID()
        {
            string resultString = "";
            string sourceString = this.AllIsolateStationEventIDs;

            string[] strEventIDs = sourceString.Split(',');

            //remove some event id.
            foreach (string item in strEventIDs)
            {
                if (item.Trim().Length > 0)
                {
                    if (resultString.IndexOf("," + item.Trim() + ",") < 0)
                    {
                        resultString = "," + item.Trim() + "," + resultString;
                    }
                }
            }

            resultString = resultString.Replace(",,", ",");

            //remove "," char at first.
            if (resultString.Trim().Length > 0 && resultString.IndexOf(",") == 0)
            {
                resultString = resultString.Substring(1);
            }

            //remove "," char at last.
            if (resultString.Trim().Length > 0 && resultString.LastIndexOf(",") == resultString.Length - 1)
            {
                resultString = resultString.Substring(0, resultString.Length - 1);
            }

            //remove current event id.
            resultString = resultString.Replace(this.StationEventID.ToString() + ",", "");

            this.AllIsolateStationEventIDs = resultString;
        }

        private void HandoverNotCheckedChanged()
        {
            if (this.chkHandoverNot.Checked && this.chkHandoverNot.Enabled)
            {
                if (!this.ReadOnly && !this.HaveParent)
                {
                    this.txtHandoverNote.Enabled = true;
                }
            }
            else
            {
                // remove dylan 20150821 for u81.1
                //if (!this.chkHandoverNot.Checked)
                //{
                //    this.txtHandoverNote.Text = "";
                //}
                this.txtHandoverNote.Enabled = false;
            }
        }

        #region Fire Zone Group Panel

        //Get fire zone group status table.
        private DataTable GetFireZoneGroupStatusTable()
        {
            if (this.Action == 1)
            {
                return MTRC.ODMS.DAL.SOM.Event.StationEventFireZoneGroupDa.GetFireZoneGroupFormCDTable(Convert.ToInt32(this.ddlFireLink.SelectedValue.ToString()));
            }
            else if (this.CalledBy == 2)
            {
                return MTRC.ODMS.DAL.SOM.Event.StationEventFireZoneGroupDa.GetFireZoneGroupFromTempData(Convert.ToInt32(this.TempID), Convert.ToInt32(this.StationEventID));
            }
            else
            {
                return MTRC.ODMS.DAL.SOM.Event.StationEventFireZoneGroupDa.GetFirelinkAndFireZoneGroupByEventID(Convert.ToInt32(this.StationEventID));
            }
        }

        //Create fire zone group panel table.
        private string CreateTable()
        {
            //StringBuilder sHtml = new StringBuilder();
            //sHtml.Append ("<table>");
            //DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDFireGroupStatus.GetFireZoneGroupStatus(Convert.ToInt32(this.ddlFireLink.SelectedValue.ToString()));
            DataTable dt = GetFireZoneGroupStatusTable();
            if (dt.Rows.Count > 0)
            {
                //add by gordon 20151029 U268
                string spaceLength = DAL.CommonData.GetNumVal("SOM_FL_ZG_HorizontalSpaceLength").ToString();
                string isolatedMessage = this.GetMessage("SOM_FireZoneGroupIsolateByOtherEvent", this.LangCode);

                int MaxRows = BLL.SOM.Event.FireProtection.GetDataColumnMax("RowNo", dt);
                int MaxSeqs = BLL.SOM.Event.FireProtection.GetDataColumnMax("SeqNo", dt);

                StringBuilder tableString = new StringBuilder();
                tableString.Append("<table id='tIsolation' cellspacing='0' cellpadding='0'>");

                string statusValue = "";


                Hashtable hashStatus = GetGroupStatusData();
                this.txtFireZonePanelData.Value = "";

                for (int i = 1; i < MaxRows + 1; i++)
                {
                    tableString.Append("<tr>");

                    for (int j = 1; j < MaxSeqs + 1; j++)
                    {
                        DataRow[] rows = dt.Select("RowNo=" + i + " and SeqNo=" + j, "SeqNo,RowNo ASC");

                        string otherEventUrl = "";

                        if (rows.Length > 0)
                        {
                            tableString.Append("<td>");
                            //tableString.Append("<span>");
                            string style = " class='Normal' ";

                            if (Convert.ToInt32(rows[0]["FireZoneGrpIDStatusID"].ToString()) == 1)
                            {
                                style = " class='Normal' ";
                            }
                            else if (Convert.ToInt32(rows[0]["FireZoneGrpIDStatusID"].ToString()) == 2)
                            {
                                //update by gordon 20151029 U268
                                //string eventIDs = BLL.SOM.Event.FireProtection.GetAllStationEventIDIsolation(this.StationEventID, Convert.ToInt32(ddlFireLink.SelectedValue), Convert.ToInt32(rows[0]["FireZoneGrpID"].ToString()));
                                string eventIDs = rows[0]["IsoleteEventID"].ToString();

                                this.AllIsolateStationEventIDs = this.AllIsolateStationEventIDs + ',' + eventIDs;

                                if (eventIDs.Length > 1)
                                {
                                    otherEventUrl = this.OtherEventUrl;
                                    otherEventUrl += eventIDs;
                                }

                                style = " class='Isolation' ";
                            }
                            else if (Convert.ToInt32(rows[0]["FireZoneGrpIDStatusID"].ToString()) == 3)
                            {
                                style = " class='Restore' ";
                            }
                            else
                            {
                                style = " class='Normal' ";
                            }

                            statusValue = rows[0]["FireZoneGrpIDStatusID"].ToString();

                            //----------------Set fire zone group status with id.-----------------------------------

                            if (GetFireZoneGroupStatus(hashStatus, rows[0]["FireZoneGrpID"].ToString().Trim()) != string.Empty)
                            {
                                if (Convert.ToInt32(GetFireZoneGroupStatus(hashStatus, rows[0]["FireZoneGrpID"].ToString().Trim())) == 1)
                                {
                                    style = " class='Normal' ";
                                }
                                else if (Convert.ToInt32(GetFireZoneGroupStatus(hashStatus, rows[0]["FireZoneGrpID"].ToString().Trim())) == 2)
                                {
                                    //update by gordon 20151029 U268
                                    //string eventIDs = BLL.SOM.Event.FireProtection.GetAllStationEventIDIsolation(this.StationEventID, Convert.ToInt32(ddlFireLink.SelectedValue), Convert.ToInt32(rows[0]["FireZoneGrpID"].ToString()));
                                    string eventIDs = rows[0]["IsoleteEventID"].ToString();

                                    if (eventIDs.Length > 1)
                                    {
                                        otherEventUrl = this.OtherEventUrl;
                                        otherEventUrl += eventIDs;
                                    }

                                    style = " class='Isolation' ";
                                }
                                else if (Convert.ToInt32(GetFireZoneGroupStatus(hashStatus, rows[0]["FireZoneGrpID"].ToString().Trim())) == 3)
                                {
                                    style = " class='Restore' ";
                                }
                                else
                                {
                                    style = " class='Normal' ";
                                }

                                statusValue = GetFireZoneGroupStatus(hashStatus, rows[0]["FireZoneGrpID"].ToString().Trim());
                            }

                            //------------------------Set end.-----------------------

                            //Set isolate all fire zone group.
                            if (this.chkIsolateAll.Checked)
                            {
                                style = " class='Isolation' ";
                                statusValue = "2";
                            }

                            //Set restore all fire zone group 
                            if (this.chkRestoreAll.Checked && Convert.ToInt32(statusValue) == 2)
                            {
                                style = " class='Restore' ";
                                statusValue = "3";
                            }


                            this.txtFireZonePanelData.Value += rows[0]["FireZoneGrpID"].ToString().Trim() + ":" + statusValue + ",";
                            //tableString.Append("<span onclick=\"changeClick(this," + "'aaaaa','" + otherEventUrl + "');\" id='lbl" + rows[0]["FireZoneGrpID"] + "'");

                            //Issue 1063 2009-03-10
                            //tableString.Append("<div style='float:left;width:150' onclick=\"changeClick(this,'" + this.GetMessage("SOM_FireZoneGroupIsolateByOtherEvent", this.LangCode) + "','" + otherEventUrl + "');\" id='lbl" + rows[0]["FireZoneGrpID"] + "'");
                            //Update By Gordon 20150708 U95
                            //tableString.Append("<span style='float:left;width:" + DAL.CommonData.GetNumVal("SOM_FL_ZG_HorizontalSpaceLength").ToString() + "px;' onclick=\"changeClick(this,'" + this.GetMessage("SOM_FireZoneGroupIsolateByOtherEvent", this.LangCode) + "','" + otherEventUrl + "');\" id='lbl" + rows[0]["FireZoneGrpID"] + "'");
                            //update by gordon 20151029 U268
                            //tableString.Append("<span style='float:left;width:" + DAL.CommonData.GetNumVal("SOM_FL_ZG_HorizontalSpaceLength").ToString() + "px;' onclick=\"changeClick(this,'" + this.GetMessage("SOM_FireZoneGroupIsolateByOtherEvent", this.LangCode) + "','" + otherEventUrl + "');CheckToPopupMessageForZoneGroup();\" id='lbl" + rows[0]["FireZoneGrpID"] + "'");
                            tableString.Append("<span style='float:left;width:" + spaceLength + "px;' onclick=\"changeClick(this,'" + isolatedMessage + "','" + otherEventUrl + "');CheckToPopupMessageForZoneGroup();\" id='lbl" + rows[0]["FireZoneGrpID"] + "'");

                            tableString.Append(style);

                            string isolationFlag = "[]";

                            if (statusValue == "2")
                            {
                                isolationFlag = "[X]";
                            }

                            //update by gordon 20151029 U268
                            //tableString.Append(" title='" + BLL.SOM.Event.FireProtection.GetFireZoneGroupKey(Convert.ToInt32(rows[0]["FireZoneGrpID"])) + "' >" + rows[0]["FireZoneGrpCode"].ToString() + isolationFlag);
                            tableString.Append(" title='" + rows[0]["DetailLocation"].ToString() + "' >" + rows[0]["FireZoneGrpCode"].ToString() + isolationFlag);

                            tableString.Append("</span>");

                            //<input runat="server" id="txt123" value="" type="hidden" />
                            string inputHtml = "<input type='hidden' runat='server' id='txt" + rows[0]["FireZoneGrpID"] + "' value='" + statusValue + "'  />";
                            tableString.Append(inputHtml);


                            //rows[0]["FireZoneGrpIDStatusID"].ToString();

                            tableString.Append("</td>");

                            otherEventUrl = "";
                        }
                        else
                        {
                            //update by gordon 20151029 U268
                            //tableString.Append("<td class='FireZoneGroupTD'><span style='float:left;width:" + DAL.CommonData.GetNumVal("SOM_FL_ZG_HorizontalSpaceLength").ToString() + "px;'>&nbsp;</span></td>");
                            tableString.Append("<td class='FireZoneGroupTD'><span style='float:left;width:" + spaceLength + "px;'>&nbsp;</span></td>");
                        }
                    }

                    tableString.Append("</tr>");
                }

                tableString.Append("</table>");

                return tableString.ToString();
            }
            else
            {
                return "";
            }
        }

        //Set table.
        //private void CreateFireZoneGroupPanel()
        private void CreateFireZoneGroupPanel(string isddlFirelinkChange = "0")//Update by jack 20151221 U290 if Fire Link, Request by Name and Request by OU/Company are disabled, they should keep disabled after refreshing.
        {
            //Clear the fire zone group status when firelink changing.
            //this.txtFireZonePanelData.Value = "";
            this.phTable.Controls.Clear();
            if (this.ddlFireLink.SelectedItem != null)
            {
                HtmlGenericControl control = new HtmlGenericControl();
                control.InnerHtml = this.CreateTable();
                this.phTable.Controls.Add(control);
            }
            // add by dylan 20151102 for u276
            //update by gordon 20151116 - update script key U23
            //Update by jack 20151221 U290 if Fire Link, Request by Name and Request by OU/Company are disabled, they should keep disabled after refreshing.
            //ToolkitScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", "showWaiting('" + this.ddlFireLink.ClientID + "','');", true);
            if (isddlFirelinkChange=="1") 
            {
                ToolkitScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "HideWait", "showWaiting('" + this.ddlFireLink.ClientID + "','','" + this.CalledBy + "');", true);
            }
            //End update by jack 20151221 U290 if Fire Link, Request by Name and Request by OU/Company are disabled, they should keep disabled after refreshing.

            //update end by gordon 20151116 - update script key U23
        }

        #endregion

        #endregion

        #region SetLanguage

        public void FireProtectionEntry_ChangeLanguage(object sender, EventArgs e)
        {
            SetLanguage();
            Display();
        }

        private void SetLanguage()
        {
            //this.LastControlID = "";//clear last activety control id. issue0979
            //Button
            this.btnAmendEventTime.ToolTip = GetLabel("SOM_AmendEventTime");

            //set hidden value for imgStaffType's tooltip
            DataTable dtEventPersonType = MTRC.ODMS.DAL.SOM.CodeSetup.CDEventPersonType.GetAll(this.LangCode, true);
            if (dtEventPersonType.Rows.Count > 0)
            {
                //string imgStaffTypeTooltip = dtEventPersonType.Rows[0]["EventPersonTypeCode"].ToString();
                this.hdnImgStaffTypeTooltip1.Value = dtEventPersonType.Rows[0]["EventPersonTypeCode"].ToString();
                this.hdnImgStaffTypeTooltip2.Value = dtEventPersonType.Rows[1]["EventPersonTypeCode"].ToString();
                this.hdnImgStaffTypeTooltip3.Value = dtEventPersonType.Rows[2]["EventPersonTypeCode"].ToString();
                this.hdnImgStaffTypeTooltip4.Value = dtEventPersonType.Rows[3]["EventPersonTypeCode"].ToString();
                //this.imgStaffType.Attributes["title"] = this.hdnImgStaffTypeTooltip4.Value;
            }


            //Label
            //---lblNOShow  /lblParentEventNo
            //------------------ Modify at 2008-12-04 (If called by AR currentEventNo and ParentEventNo location set crossing-over.)-

            if (this.CalledBy == 2)
            {
                this.lblEventNO.Text = GetLabel("SOM_AdmissionRegistryNo", true);
                this.lblAdmissionRegistry.Text = GetLabel("SOM_EventNo", true);
            }
            else
            {
                this.lblEventNO.Text = GetLabel("SOM_EventNo", true);
                this.lblAdmissionRegistry.Text = GetLabel("SOM_AdmissionRegistryNo", true);
            }

            //------------------ End modify at 2008-12-04 ----------------------------

            this.lblStation.Text = GetLabel("SOM_Station", true);
            //update by gordon 20150815
            //this.lblIsolationTime.Text = GetLabel("COM_IsolationTime", true);
            this.lblIsolationTime.Text = GetLabel("COM_IsolationTimeEntry", true);
            this.lblHour.Text = GetLabel("SOM_Hours", false);
            this.lblIsolationDuration.Text = GetLabel("COM_IsolationDuration", true);
            this.lblRequestByID.Text = GetLabel("SOM_RequestByID", true);
            this.lblRequestByName.Text = GetLabel("SOM_RequestByName", true);
            this.lblRequestByDeptCompany.Text = GetLabel("SOM_RequestByDept", true);
            this.lblRequestByOU.Text = GetLabel("SOM_RequestByOU", true);
            this.lblRequestByContactNumber.Text = GetLabel("SOM_RequestByContactNumber", true);
            this.lblHandledby.Text = GetLabel("LPM_HandledBy", true);
            /*Comment by jack 20151021 for u256*/
            //this.btnSelectRequest.ToolTip = this.GetLabel("SOM_OpenStaffSelectionForm");
            this.btnSelectRequest.ToolTip = this.GetLabel("SOM_ImgSearchStaff");
            /***********************************/
            //this.imgSelectResponsible.ToolTip = this.GetLabel("SOM_OpenStaffSelectionForm");

            //update by gordon 20150806 U133
            //this.lblFireLinkCoordinator.Text = GetLabel("SOM_FirelinkCoordinator", true);//BJL4 or HK 
            this.lblFireLinkCoordinator.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true);//BJL4 or HK 

            this.lblFireLink.Text = this.GetLabel("SOM_FireLink", true);

            this.lblStatus.Text = GetLabel("SOM_FireLinkStatus", true);//BJL4 or HK

            this.lblRestoreTime.Text = GetLabel("SOM_RestoreTime", true);
            this.lblIsolateFireZoneGroup.Text = GetLabel("SOM_IsolateFireZoneGroup", true);
            this.lblGoToAdmission.Text = GetLabel("SOM_GoToAdmissionRegistry", this.LangCode);
            this.lblReason.Text = GetLabel("SOM_Reason", true);
            this.lblRemarks.Text = GetLabel("SOM_Remark", true);

            // update by dylan 20150704 for u61
            // this.lblHandoverNote.Text = GetLabel("SOM_HandoverNote", true);
            this.lblHandoverNote.Text = GetLabel("SOM_HandoverCheck", true);

            this.lblFieldSetFireZoneGroupStatusControl.Text = GetLabel("SOM_FieldSetFireZoneGroupStatusControl", this.LangCode);
            this.lblFieldSetFireSystemStatusControl.Text = GetLabel("SOM_FieldSetFireSystemStatusControl", this.LangCode);

            DataTable dtZoneStatus = DAL.SOM.CodeSetup.CDFireGroupStatus.GetFireZoneGroupStatusBylangCode(this.LangCode);
            this.lblNormal.Text = dtZoneStatus.Rows[0]["Normal"].ToString();
            this.lblIsolate.Text = dtZoneStatus.Rows[0]["Isolated"].ToString();
            this.lblRestore.Text = dtZoneStatus.Rows[0]["Restored"].ToString();

            //CheckBox
            this.chkIsolateAll.Text = GetLabel("SOM_IsolateAll");
            this.chkRestoreAll.Text = GetLabel("SOM_RestoreAll");
            this.chkRestoreNormal.Text = GetLabel("SOM_RestoreNormal");

            //Add by gordon 20150707 U95
            this.lblRestoreCHUBB.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true);
            this.lblRestoreHandleBy.Text = GetLabel("SOM_FireLinkRestoreHandleBy", true);


            //this.imgAssetLoanEventStatusNew.Attributes.Add("title", this.GetEventStatusDesc(this.EventStatusID, this.LangCode));//add at 2008-12-10


            //------------------------ modify at 2008-12-10 ---------------------------

            //System.Data.SqlClient.SqlDataReader dReader = BLL.SOM.Event.StationEventAdmReg.AREntryGeneralReader(this.StationEventID, this.LangCode);

            //if (dReader.HasRows)
            //{
            //    dReader.Read();

            //    //this.imgAssetLoanEventStatus.Attributes.Add("title", dReader["EventStatusDesc"].ToString());
            //    this.imgAssetLoanEventStatusNew.Attributes.Add("title", dReader["EventStatusDesc"].ToString());//add at 2008-12-04
            //}

            //dReader.Close();

            //------------------------ modify at 2008-12-10 ---------------------------

            this.imgResponsibleStaffType.ToolTip = hdnImgStaffTypeTooltip1.Value;

            SetRequestPersonTypeICO();
        }

        #endregion

        #region Some Event

        //select responsible by event.
        protected void imgSelectResponsible_Click(object sender, ImageClickEventArgs e)
        {
            /*
              -------------- Modify at 2008-11-20 -----------------
             
            if (this.hdnResponsibleByType.Value.ToString().Trim().Length > 0)
            {
                if (this.hdnResponsibleByType.Value.ToString().Trim() == "1")
                {
                    this.imgResponsibleStaffType.ImageUrl = "../../Images/SOM/StaffType_Staff.gif";
                }
                else if (this.hdnResponsibleByType.Value.ToString().Trim() == "2")
                {
                    this.imgResponsibleStaffType.ImageUrl = "../../Images/SOM/StaffType_CQAContractor.gif";
                }
                else if (this.hdnResponsibleByType.Value.ToString().Trim() == "3")
                {
                    this.imgResponsibleStaffType.ImageUrl = "../../Images/SOM/StaffType_StationContractor.gif";
                }
                else //4
                {
                    this.imgResponsibleStaffType.ImageUrl = "../../Images/SOM/StaffType_AddHoc.gif";
                }

                //this.imgStaffType.Attributes["title"] = imgStaffTypeTooltip;
            }
             * */
        }

        //select request by event.
        protected void btnSelectRequest_Click(object sender, ImageClickEventArgs e)
        {
            SetRequestPersonTypeICO();
        }

        //Amend event time.
        protected void btnAmendEventTime_Click(object sender, EventArgs e)
        {
            //Issue U05:Delete by Gordon 2015/05/21
            //if (this.txtIsolationDuration.Text.Trim() != string.Empty)
            //{
            //    //SHould use regx to judge the input data format whether or not match up the right format, #.#, 1 bit decimal
            //    string matchStr = @"^[0-9]+(.[0-9]{1})?$";
            //    System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex(matchStr);
            //    if (!regx.IsMatch(txtIsolationDuration.Text.Trim()))
            //    {
            //        this.txtIsolationDuration.Text = "0";
            //        this.PAlert(this.GetMessage("SOM_EstimateCompletionDateTimeHrsCheck"), 0, this.txtIsolationDuration);
            //    }
            //    else
            //    {
            //        float result;
            //        bool isNum = float.TryParse(txtIsolationDuration.Text.Trim(), out result);
            //        if (isNum)
            //        {
            //            if (result > 9999.9f)//2015/05/13 Kingkong said:Isolation Duration max valus is 9999.9
            //            {
            //                this.txtIsolationDuration.Text = "0";
            //                this.PAlert(this.GetMessage("SOM_IsolationDuration_Range"), 0, this.txtIsolationDuration);
            //            }
            //        }
            //    }
            //}
            //else
            //{
            //    this.txtIsolationDuration.Text = "0";
            //}

            if (string.IsNullOrEmpty(this.txtIsolationDuration.Text.Trim()))
            {
                this.txtIsolationDuration.Text = "0";
            }

            if (this.txtIsolationDateTime.Text.Trim().Length > 0)
            {
                DateTime dateTime = this.ConvertToDateTime(txtIsolationDateTime.Text.Trim());
                float hr = this.txtIsolationDuration.Text.Trim().Length > 0 ? float.Parse(txtIsolationDuration.Text.Trim()) : 0f;
                dateTime = dateTime.AddMinutes(hr * 60);
                this.lblEstimatedIsolationDate.Text = this.FormatDateTime(dateTime, true);
            }
        }

        //Check staff and get staff informatin.
        protected void txtRequestByID_TextChanged(object sender, EventArgs e)
        {
            if (this.txtRequestByID.Text.Trim().Length > 0)
            {
                int extPartyStaffSnapShotID = this.hdnExtPartyStaffSnapShotID.Value.Length > 0 ? Convert.ToInt32(this.hdnExtPartyStaffSnapShotID.Value) : 0;
                ODMS.Model.SOM.CodeSetup.CDStaffInfo staffInfo = DAL.SOM.CodeSetup.CdStaffInfo.SearchStaffInfo(this.txtRequestByID.Text.Trim(), this.LangCode, false, extPartyStaffSnapShotID);

                if (staffInfo == null || staffInfo.StaffID.ToString().Trim().Length < 1)
                {
                    staffInfo = DAL.SOM.CodeSetup.CdStaffInfo.SearchStaffInfo(this.txtRequestByID.Text.Trim(), this.LangCode, false, 0);
                }

                //add by gordon 20150722
                if (staffInfo != null && staffInfo.EventPersonTypeID == 3)
                {
                    this.hdnRequestStaffOrExtPartyID.Value = staffInfo.StaffOrExtPartyID.ToString();
                    this.hdnExtPartyStaffSnapShotID.Value = staffInfo.ExtPartyStaffSnapShotID.ToString();
                    this.hdnStaffType.Value = staffInfo.EventPersonTypeID.ToString();
                    SetRequestPersonTypeICO();
                    SetRequestReadOnly(true);
                    return;
                }

                //U235 benson 2015-10-15  begin
                //if (staffInfo != null && staffInfo.EventPersonTypeID == 5)
                //{
                //    //exists, but not a valid staff or obsolete, or status set to T
                //    //this.Alert("Staff had been invalid or set as obsolete!");
                //    this.txtRequestByID.Text = ""; //huangyao 20100326 issue 1399
                //    this.PAlert(this.GetMessage("SOM_SelectedAnVoidStaffMsg"));

                //    this.txtRequestByContactNumber.Text = "";
                //    this.txtRequestByDept.Text = "";
                //    this.txtRequestByName.Text = "";
                //    this.txtRequestByOU.Text = "";
                //    this.hdnRequestStaffOrExtPartyID.Value = "0";
                //    this.hdnStaffType.Value = "4";//hardcode
                //    this.chkRestoreNormal.Checked = false;
                //    this.hdnExtPartyStaffSnapShotID.Value = "0";
                //    SetRequestPersonTypeICO();//set request person type icon.
                //    SetRequestReadOnly(false);

                //    return;
                //}
                //U235 benson 2015-10-15  end


                //update by gordon 20150722 Add Condition [staffInfo.EventPersonTypeID == 1]
                //update by gordon 20150817 delete Condition [staffInfo.EventPersonTypeID == 1]
                if (staffInfo != null && staffInfo.StaffID.ToString().Trim().Length > 0) //Not exist current staff information.
                {
                    //this.txtRequestByContactNumber.Text = staffInfo.Tel; //Issue U38: Delete By Gordon 2015/05/28
                    //Add By Gordon 20150702 U103
                    if (staffInfo.EventPersonTypeID != 3)
                        this.txtRequestByContactNumber.Text = "";

                    //update by gordon 20150710 orgunit instead of depart
                    if (staffInfo.EventPersonTypeID == 3 || staffInfo.EventPersonTypeID == 2)
                        this.txtRequestByDept.Text = staffInfo.DepartmentCompany;
                    else
                        this.txtRequestByDept.Text = staffInfo.OrganizationUnit;

                    this.hdnStaffType.Value = staffInfo.EventPersonTypeID.ToString();
                    this.hdnRequestStaffOrExtPartyID.Value = staffInfo.StaffOrExtPartyID.ToString();
                    this.txtRequestByID.Text = staffInfo.StaffID;
                    this.txtRequestByName.Text = staffInfo.StaffName;
                    this.txtRequestByOU.Text = staffInfo.OrganizationUnit;
                    this.hdnExtPartyStaffSnapShotID.Value = staffInfo.ExtPartyStaffSnapShotID.ToString();
                    SetRequestReadOnly(true);
                    SetRequestPersonTypeICO();
                }
                else
                {
                    this.txtRequestByContactNumber.Text = "";
                    this.txtRequestByDept.Text = "";
                    this.txtRequestByName.Text = "";
                    this.txtRequestByOU.Text = "";
                    this.hdnRequestStaffOrExtPartyID.Value = "0";
                    this.hdnStaffType.Value = "4";//hardcode
                    this.chkRestoreNormal.Checked = false;
                    this.hdnExtPartyStaffSnapShotID.Value = "0";
                    SetRequestPersonTypeICO();//set request person type icon.
                    SetRequestReadOnly(false);
                }
            }
            else//--------------- Add at 2009-02-12 issue 1008 -----------------
            {
                this.txtRequestByContactNumber.Text = "";
                this.txtRequestByDept.Text = "";
                this.txtRequestByName.Text = "";
                this.txtRequestByOU.Text = "";
                this.hdnRequestStaffOrExtPartyID.Value = "0";
                this.hdnStaffType.Value = "4";//hardcode
                this.hdnExtPartyStaffSnapShotID.Value = "0";
                SetRequestPersonTypeICO();//set request person type icon.
            }//-------------- End add at 2009-02-12 issue 1008 ----------------

            //string script = "<script>SetCursorOff();</script>";
            //ScriptManager.RegisterClientScriptBlock(panel11, Page.GetType(), "", script, false);

            string script = "<script>SetCursorOff();</script>";
            ScriptManager.RegisterClientScriptBlock(panel11, Page.GetType(), "", script, false);
        }

        //Selected station changed.
        protected void ddlStation_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.txtFireZonePanelData.Value = "";
            this.chkIsolateAll.Checked = false;
            this.chkRestoreAll.Checked = false;

            BindFireLink();
            CreateFireZoneGroupPanel();
        }

        //Selected fire link changed.
        protected void ddlFireLink_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.txtFireZonePanelData.Value = "";
            this.chkIsolateAll.Checked = false;
            this.chkRestoreAll.Checked = false;

            //CreateFireZoneGroupPanel();
            CreateFireZoneGroupPanel("1");//Update by jack 20151221 U290 if Fire Link, Request by Name and Request by OU/Company are disabled, they should keep disabled after refreshing.


        }
        //restore all fire zone group.
        protected void chkRestoreAll_CheckedChanged(object sender, EventArgs e)
        {
            this.txtFireZonePanelData.Value = "";
            this.chkIsolateAll.Checked = false;
            CreateFireZoneGroupPanel();

            if (this.Action == 2 && rblStatus.SelectedValue == "1" && this.StationEventID != -1)
            {
                //add by gordon 20150708 U95
                SetRestoreControl(chkRestoreAll.Checked);
                //delete by gordon 20150804 U127.3
                //if (chkRestoreAll.Checked)
                //{
                //    ShowOutStandingMessage();
                //}
            }
            else
            {
                //add by gordon 20150814 U146
                if (!chkRestoreAll.Checked)
                {
                    chkRestoreNormal.Checked = false;
                    chkRestoreNormal_CheckedChanged(null, null);
                }
            }

            //add by gordon 20150804 U127.3
            if (this.Action == 2 && rblStatus.SelectedValue != "1")
            {
                if (chkRestoreAll.Checked)
                {
                    ShowOutStandingMessage();
                }
            }
        }

        //Isolate all fire zone group.
        protected void chkIsolateAll_CheckedChanged(object sender, EventArgs e)
        {
            this.txtFireZonePanelData.Value = "";
            this.chkRestoreAll.Checked = false;

            CreateFireZoneGroupPanel();

            //add by gordon 20150708 U95
            if (chkIsolateAll.Checked)
            {
                SetRestoreControl(false);
                chkRestoreNormal.Checked = false;
                this.lblCompleteRestoreTime.Text = "";
            }
        }

        //Restore Normal
        protected void chkRestoreNormal_CheckedChanged(object sender, EventArgs e)
        {
            if (this.chkRestoreNormal.Checked)
            {
                this.lblCompleteRestoreTime.Text = FormatDateTime(DAL.COM.Util.GetCurrentSystemTime(), true);
                //add by gordon 20150708 U95
                SetRestoreControl(true);

                //update by gordon 20150804 U127.3
                if (rblStatus.SelectedValue != "1")
                {
                    //add by gordon 20150708 U36
                    ShowOutStandingMessage();
                }
            }
            else
            {
                this.lblCompleteRestoreTime.Text = "";
                //add by gordon 20150708 U95
                SetRestoreControl(false);
            }
        }

        protected void rblStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.rblStatus.SelectedValue != "1")
            {
                this.chkRestoreNormal.Checked = false;
                this.lblCompleteRestoreTime.Text = "";
            }

            /* Update by jack 20150527 for U30 */
            //if (this.rblStatus.SelectedValue != "2") {
            //    this.lblFireLinkCoordinator.Text = GetLabel("SOM_FirelinkCoordinator", true);
            //}
            DataTable dt = MTRC.ODMS.DAL.SOM.Event.StationEventFireZoneGroupDa.GetStatusIDByCode(DAL.CommonData.GetStrVal("SOM_FireLink_MandatoryCHUBB"), 1);
            bool isSelected = false;
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (this.rblStatus.SelectedValue.Trim().Equals(dt.Rows[i][0].ToString().Trim()))
                    {
                        isSelected = true;
                    }
                }
            }
            if (isSelected)
            {
                //update by gordon 20150806 U133
                //this.lblFireLinkCoordinator.Text = GetLabel("SOM_FirelinkCoordinator", true) + "<em>*</em>";
                this.lblFireLinkCoordinator.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true) + "<em>*</em>";
                //Add by gordon 20150707
                if (txtRestoreCHUBB.Enabled)
                {
                    this.lblRestoreCHUBB.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true) + "<em>*</em>";
                }
            }
            else
            {
                //update by gordon 20150806 U133
                //this.lblFireLinkCoordinator.Text = GetLabel("SOM_FirelinkCoordinator", true);
                this.lblFireLinkCoordinator.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true);
                //Add by gordon 20150707
                this.lblRestoreCHUBB.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true);
            }
            /********************************/

            /* add by jack 20150527 for U31 */
            DataTable dtIsolationDuration = MTRC.ODMS.DAL.SOM.Event.StationEventFireZoneGroupDa.GetStatusIDByCode(DAL.CommonData.GetStrVal("SOM_FireLink_DefaultIsolationDuration"), 2);
            bool isSelectIsolationDuration = false;
            if (dtIsolationDuration.Rows.Count > 0)
            {
                for (int i = 0; i < dtIsolationDuration.Rows.Count; i++)
                {
                    if (this.rblStatus.SelectedValue.Trim().Equals(dtIsolationDuration.Rows[i][0].ToString().Trim()))
                    {
                        this.txtIsolationDuration.Text = dtIsolationDuration.Rows[i][2].ToString().Trim();
                        isSelectIsolationDuration = true;
                    }
                }
            }
            if (!isSelectIsolationDuration)
            {
                //this.txtIsolationDuration.Text = "0";
            }
            /********************************/

            /* add by jack 20150527 for U41 &109 */
            //if (this.rblStatus.SelectedValue != "1")
            //{
            //    this.chkRestoreNormal.Enabled = true;
            //}
            //if (this.rblStatus.SelectedValue == "1")
            //{
            //    this.chkRestoreNormal.Enabled = false;
            //}
            /********************************/

            //Add By Gordon 20150701 Bind New Time After Change Isolation Time
            btnAmendEventTime_Click(null, null);
        }

        //Handover check event.
        protected void chkHandoverNot_CheckedChanged(object sender, EventArgs e)
        {
            HandoverNotCheckedChanged();
        }


        #region menu event function

        public void btnSave_Click(bool flagNew)
        {
            Model.SOM.Event.FireProtectionInfo fireProtectionInfo = new MTRC.ODMS.Model.SOM.Event.FireProtectionInfo();

            if (Action == 1)
            {
                #region New

                fireProtectionInfo.LocationID = Convert.ToInt32(ddlStation.SelectedValue);
                fireProtectionInfo.IsolateReasonID = Convert.ToInt32(ddlReason.SelectedValue);
                fireProtectionInfo.FirelinkID = Convert.ToInt32(ddlFireLink.SelectedValue);
                fireProtectionInfo.FireLinkStatusID = Convert.ToInt32(rblStatus.SelectedValue);
                fireProtectionInfo.EventTime = this.ConvertToDateTime(this.txtIsolationDateTime.Text);
                fireProtectionInfo.EventInitTime = this.ConvertToDateTime(this.hdnInitDateTime.Value);
                Session["AR_FireInitDateTime"] = this.hdnInitDateTime.Value; //Add by jack 20151223 U291 The amendment history on isolation time is incorrect.
                //fireProtectionInfo.EventInitTime = this.ConvertToDateTime(this.hdnInitDateTime.Value).AddMinutes(float.Parse(this.txtIsolationDuration.Text) * 60); //midfy by 2008-10-23
                fireProtectionInfo.EstimatedWrkHour = float.Parse(this.txtIsolationDuration.Text);
                //fireProtectionInfo.EventTime = this.ConvertToDateTime(this.lblEstimatedIsolationDate.Text);
                fireProtectionInfo.RequestStaffID = this.txtRequestByID.Text;
                fireProtectionInfo.RequestByName = this.txtRequestByName.Text;
                fireProtectionInfo.RequestCompany = this.txtRequestByDept.Text;
                fireProtectionInfo.Tel = this.txtRequestByContactNumber.Text;
                //fireProtectionInfo.OrganizationUnit = this.txtRequestByOU.Text;
                fireProtectionInfo.RequestByContactNo = this.txtRequestByContactNumber.Text;
                fireProtectionInfo.ResponsibleByName = this.ddlHandledby.SelectedItem.Text;
                fireProtectionInfo.FirelinkCoordinator = this.txtFirelinkCoordinator.Text;
                fireProtectionInfo.Remark = this.txtRemarks.Text;
                fireProtectionInfo.Description = this.txtRemarks.Text;
                fireProtectionInfo.UserGroup = this.ODMUser.UserGroupID;
                fireProtectionInfo.LangCode = this.LangCode;
                fireProtectionInfo.UserID = this.ODMUser.ID;
                fireProtectionInfo.AmendReason = this.hdnDateTimeReason.Value;
                fireProtectionInfo.RequestPersonType = this.hdnStaffType.Value.Length > 0 ? Convert.ToInt32(this.hdnStaffType.Value) : 4;//hard code 4.
                fireProtectionInfo.ResponsiblePersonType = this.hdnResponsibleByType.Value.Length > 0 ? Convert.ToInt32(this.hdnResponsibleByType.Value) : 1;
                fireProtectionInfo.RequestStaffOrExtPartyID = this.hdnRequestStaffOrExtPartyID.Value.Length > 0 ? Convert.ToInt32(this.hdnRequestStaffOrExtPartyID.Value) : 0;
                fireProtectionInfo.ResponsibleStaffOrExtPartyID = this.hdnResponsibleStaffOrExtPartyID.Value.Length > 0 ? Convert.ToInt32(this.hdnResponsibleStaffOrExtPartyID.Value) : 0;
                fireProtectionInfo.FlagRestore = chkRestoreNormal.Checked;
                fireProtectionInfo.FlagHandover = this.chkHandoverNot.Checked;
                fireProtectionInfo.AmendTimeReason = this.hdnDateTimeReason.Value;
                fireProtectionInfo.ExtPartyStaffSnapShotID = this.hdnExtPartyStaffSnapShotID.Value.Trim().Length > 0 ? Convert.ToInt32(this.hdnExtPartyStaffSnapShotID.Value.Trim()) : 0;
                //Add by gordon 20150707 U95
                fireProtectionInfo.RestoreHandleByID = 0;// int.Parse(ddlRestoreHandleBy.SelectedValue);
                fireProtectionInfo.RestoreCHUBB = txtRestoreCHUBB.Text;
                fireProtectionInfo.ResponsiblePersonID = int.Parse(ddlHandledby.SelectedValue);

                if (this.chkHandoverNot.Checked)
                {
                    fireProtectionInfo.HandoverNotedate = this.txtHandoverNote.Text;
                }

                DataTable tempDataTable = GetFireZoneGroupStatusTable();


                if (this.CalledBy == 1)
                {
                    //From Fire protection

                    #region From Fire Protection

                    ArrayList fireZoneGroupList = DataTableConvertToFireZoneGroup(tempDataTable);

                    if (this.chkRestoreNormal.Checked)
                    {
                        fireProtectionInfo.RestoreTime = this.ConvertToDateTime(lblCompleteRestoreTime.Text);
                        fireProtectionInfo.FlagRestore = true;

                        bool existIsolete = false;

                        //------Exist Isolete Fire Zone Group-------
                        for (int i = 0; i < fireZoneGroupList.Count; i++)
                        {
                            Model.SOM.Event.StationEventFireZoneGroupInfo itemFireZoneGroupInfo = (Model.SOM.Event.StationEventFireZoneGroupInfo)fireZoneGroupList[i];

                            if (itemFireZoneGroupInfo.FireZoneGrpIDStatusID == 2)
                            {
                                existIsolete = true;

                                break;
                            }
                        }
                        //----------------End-------------------

                        //set complete.
                        if (this.lblCompleteRestoreTime.Text.Trim().Length > 0 && !existIsolete)
                        {
                            fireProtectionInfo.FlagComplete = true;
                            fireProtectionInfo.EventStatusID = 2;
                            fireProtectionInfo.EventCompleteTime = this.ConvertToDateTime(lblCompleteRestoreTime.Text);
                        }
                    }

                    int newStationEventID = BLL.SOM.Event.FireProtection.Insert(fireProtectionInfo, fireZoneGroupList, this.ODMUser);
                    this.StationEventID = newStationEventID;
                    //Response.Redirect("FireProtectionEntry.aspx?StationEventID=" + newStationEventID + "&Action=Edit");

                    #endregion

                }
                else if (this.CalledBy == 2)//AR
                {
                    #region From AR

                    this.StationEventID = DAL.SOM.TempData.GetStationEventIDFormTempData(this.TempID);
                    fireProtectionInfo.StationEventID = this.StationEventID;

                    DataTable dtFireZoneGroup = GetFireZoneGroup();

                    if (this.chkRestoreNormal.Checked)
                    {
                        fireProtectionInfo.RestoreTime = this.ConvertToDateTime(lblCompleteRestoreTime.Text);
                        fireProtectionInfo.FlagRestore = true;


                        //------Exist Isolete Fire Zone Group-------

                        bool existIsolete = false;
                        foreach (DataRow dr in dtFireZoneGroup.Rows)
                        {
                            if (dr["FireZoneGrpIDStatusID"].ToString().Trim().Length > 0)
                            {
                                if (Convert.ToInt16(dr["FireZoneGrpIDStatusID"]) == 2)
                                {
                                    existIsolete = true;

                                    break;
                                }
                            }
                        }

                        //-------------End---------------

                        //set complete.
                        if (this.lblCompleteRestoreTime.Text.Trim().Length > 0 && !existIsolete)
                        {
                            fireProtectionInfo.FlagComplete = true;
                            fireProtectionInfo.EventStatusID = 2;
                            fireProtectionInfo.EventCompleteTime = this.ConvertToDateTime(lblCompleteRestoreTime.Text);
                        }
                    }

                    if (this.FirstCall)//First Add New.
                    {
                        //update by gordon 20150818 U125.1
                        //BLL.SOM.Event.FireProtection.InsertTempData_EventData(Convert.ToInt32(this.TempID), GetStationEvent(), GetStationEventFirelink(), GetFireZoneGroup(), GetStationEventPerson(), GetStationEventAmendTime());
                        BLL.SOM.Event.FireProtection.InsertTempData_EventData(Convert.ToInt32(this.TempID), GetStationEvent(), GetStationEventFirelink(), GetFireZoneGroup(), GetStationEventPerson(), GetStationEventAmendTime(), GetEventTimeAndUserGroupID());

                        //Response.Redirect("FireProtectionEntry.aspx?StationEventID=" + this.StationEventID + "&Action=Edit&tempID=" + this.TempID + "&ParentStationEventID=" + this.ParentEventID + "&ParentStationEventNo=" + this.ParentEventNo);
                    }
                    else if (Action == 1)
                    {
                        //update by gordon 20150818 U125.1
                        //BLL.SOM.Event.FireProtection.InsertTempData_EventData(Convert.ToInt32(this.TempID), GetStationEvent(), GetStationEventFirelink(), GetFireZoneGroup(), GetStationEventPerson(), GetStationEventAmendTime());
                        BLL.SOM.Event.FireProtection.InsertTempData_EventData(Convert.ToInt32(this.TempID), GetStationEvent(), GetStationEventFirelink(), GetFireZoneGroup(), GetStationEventPerson(), GetStationEventAmendTime(), GetEventTimeAndUserGroupID());

                        //Response.Redirect("FireProtectionEntry.aspx?StationEventID=" + this.StationEventID + "&Action=Edit&tempID=" + this.TempID + "&ParentStationEventID=" + this.ParentEventID + "&ParentStationEventNo=" + this.ParentEventNo);
                    }
                    else
                    {
                        //update by gordon 20150818 U125.1
                        //BLL.SOM.Event.FireProtection.UpdateTempData_EventData(Convert.ToInt32(this.TempID), Convert.ToInt32(this.StationEventID), GetStationEvent(), GetStationEventFirelink(), GetFireZoneGroup(), GetStationEventPerson(), GetStationEventAmendTime());
                        BLL.SOM.Event.FireProtection.UpdateTempData_EventData(Convert.ToInt32(this.TempID), Convert.ToInt32(this.StationEventID), GetStationEvent(), GetStationEventFirelink(), GetFireZoneGroup(), GetStationEventPerson(), GetStationEventAmendTime(), GetEventTimeAndUserGroupID());
                        //Response.Redirect("FireProtectionEntry.aspx?StationEventID=" + this.StationEventID + "&Action=Edit&tempID=" + this.TempID + "&ParentStationEventID=" + this.ParentEventID + "&ParentStationEventNo=" + this.ParentEventNo);
                    }//flagNew

                    if (flagNew)
                    {
                        string q_StatffID = Request.QueryString["StatffID"] != null ? Request.QueryString["StatffID"].ToString() : "";
                        string q_txtIsolationDateTime = Request.QueryString["txtIsolationDateTime"] != null ? Request.QueryString["txtIsolationDateTime"].ToString() : "";
                        string q_imgRequesSrc = Request.QueryString["imgRequesSrc"] != null ? Request.QueryString["imgRequesSrc"].ToString() : "";
                        string q_txtRequestByName = Request.QueryString["txtRequestByName"] != null ? Request.QueryString["txtRequestByName"].ToString() : "";
                        string q_txtRequestByDept = Request.QueryString["txtRequestByDept"] != null ? Request.QueryString["txtRequestByDept"].ToString() : "";
                        string q_txtRequestByOU = Request.QueryString["txtRequestByOU"] != null ? Request.QueryString["txtRequestByOU"].ToString() : "";
                        string q_txtRequestByContactNumber = Request.QueryString["txtRequestByContactNumber"] != null ? Request.QueryString["txtRequestByContactNumber"].ToString() : "";
                        string q_txtIsolationDuration = Request.QueryString["txtIsolationDuration"] != null ? Request.QueryString["txtIsolationDuration"].ToString() : "";
                        string q_lblEstimatedIsolationDate = Request.QueryString["lblEstimatedIsolationDate"] != null ? Request.QueryString["lblEstimatedIsolationDate"].ToString() : "";
                        string q_chkHandoverCheck = Request.QueryString["chkHandoverCheck"] != null ? Request.QueryString["chkHandoverCheck"].ToString() : "";
                        string q_txtHandoverNote = Request.QueryString["txtHandoverNote"] != null ? Request.QueryString["txtHandoverNote"].ToString() : "";
                        string q_hdnInitDateTime = Request.QueryString["hdnInitDateTime"] != null ? Request.QueryString["hdnInitDateTime"].ToString() : "";
                        string q_hdnRequestStaffOrExtPartyID = Request.QueryString["hdnRequestStaffOrExtPartyID"] != null ? Request.QueryString["hdnRequestStaffOrExtPartyID"].ToString() : "";

                        string redirectUrl = "PopupARFirePortection.aspx?Action=New&ParentStationEventID=" + this.ParentEventID + "&ParentEventNo=" + this.ParentEventNo + "&tempID=" + this.TempID + "&StationEventID=-1" + "&StatffID=" + q_StatffID + "&txtIsolationDateTime=" + q_txtIsolationDateTime + "&imgRequesSrc=" + q_imgRequesSrc + "&txtRequestByName=" + q_txtRequestByName + "&txtRequestByDept=" + q_txtRequestByDept + "&txtRequestByOU=" + q_txtRequestByOU + "&txtRequestByContactNumber=" + q_txtRequestByContactNumber + "&txtIsolationDuration=" + q_txtIsolationDuration + "&lblEstimatedIsolationDate=" + q_lblEstimatedIsolationDate + "&chkHandoverCheck=" + q_chkHandoverCheck + "&txtHandoverNote=" + q_txtHandoverNote + "&hdnInitDateTime=" + q_hdnInitDateTime + "&hdnRequestStaffOrExtPartyID=" + q_hdnRequestStaffOrExtPartyID;

                        Response.Redirect(redirectUrl);

                        //Response.Redirect("PopupARFirePortection.aspx?StationEventID=" + this.StationEventID + "&Action=New&tempID=" + this.TempID + "&ParentStationEventID=" + this.ParentEventID + "&ParentStationEventNo=" + this.ParentEventNo);
                    }
                    //else
                    //{
                    //    Response.Redirect("PopupARFirePortection.aspx?StationEventID=" + this.StationEventID + "&Action=Edit&tempID=" + this.TempID + "&ParentStationEventID=" + this.ParentEventID + "&ParentStationEventNo=" + this.ParentEventNo);
                    //}

                    #endregion
                }

                #endregion
            }
            else
            {
                #region Edit

                //------------ Add at 2008-12-08 (action log 0736) -------------

                if (Convert.ToInt16(hidAutomaticallyAssignTestoreTime.Value) > 0)
                {
                    this.chkRestoreNormal.Checked = true;
                    this.lblCompleteRestoreTime.Text = this.FormatDateTime(MTRC.ODMS.DAL.COM.Util.GetCurrentSystemTime(), true);
                }

                //------------ End add at 2008-12-08 (action log 0736) -------------

                fireProtectionInfo.LocationID = Convert.ToInt32(ddlStation.SelectedValue);
                fireProtectionInfo.IsolateReasonID = Convert.ToInt32(ddlReason.SelectedValue);
                fireProtectionInfo.FirelinkID = Convert.ToInt32(ddlFireLink.SelectedValue);
                fireProtectionInfo.FireLinkStatusID = Convert.ToInt32(rblStatus.SelectedValue);
                fireProtectionInfo.StationEventID = Convert.ToInt32(this.StationEventID);
                //update by gordon 20150813
                //fireProtectionInfo.EventNo = this.lblParentEventNo.Text.Trim().Length > 0 ? this.lblParentEventNo.Text : fireProtectionInfo.EventNo;
                fireProtectionInfo.EventNo = this.lblParentEventNo.Text.Trim().Length > 0 ? this.lblParentEventNo.Text : string.IsNullOrEmpty(lblNOShow.Text.Trim()) ? fireProtectionInfo.EventNo : lblNOShow.Text.Trim();
                fireProtectionInfo.EventInitTime = this.ConvertToDateTime(this.hdnInitDateTime.Value);
                fireProtectionInfo.EventTime = this.ConvertToDateTime(this.txtIsolationDateTime.Text);//modify 2008-10-24 
                
                //fireProtectionInfo.EventTime = this.ConvertToDateTime(this.lblEstimatedIsolationDate.Text);

                fireProtectionInfo.EstimatedWrkHour = float.Parse(this.txtIsolationDuration.Text);

                fireProtectionInfo.RequestStaffID = this.txtRequestByID.Text;
                fireProtectionInfo.RequestByName = this.txtRequestByName.Text;
                fireProtectionInfo.RequestCompany = this.txtRequestByDept.Text;
                fireProtectionInfo.AmendReason = this.hdnDateTimeReason.Value;
                //fireProtectionInfo.OrganizationUnit = this.txtRequestByOU.Text;
                fireProtectionInfo.RequestByContactNo = this.txtRequestByContactNumber.Text;
                fireProtectionInfo.ResponsibleByName = this.ddlHandledby.SelectedItem.Text;
                fireProtectionInfo.FirelinkCoordinator = this.txtFirelinkCoordinator.Text;
                fireProtectionInfo.FlagHandover = this.chkHandoverNot.Checked;
                fireProtectionInfo.HandoverNotedate = this.txtHandoverNote.Text;
                fireProtectionInfo.Tel = this.txtRequestByContactNumber.Text;
                fireProtectionInfo.Remark = this.txtRemarks.Text;
                fireProtectionInfo.UserID = this.ODMUser.ID;
                fireProtectionInfo.UserGroup = this.ODMUser.UserGroupID;
                fireProtectionInfo.RequestPersonType = this.hdnStaffType.Value.Length > 0 ? Convert.ToInt32(this.hdnStaffType.Value) : 4;//hard code 4.
                fireProtectionInfo.ResponsiblePersonType = this.hdnResponsibleByType.Value.Length > 0 ? Convert.ToInt32(this.hdnResponsibleByType.Value) : 1;
                fireProtectionInfo.RequestStaffOrExtPartyID = this.hdnRequestStaffOrExtPartyID.Value.Length > 0 ? Convert.ToInt32(this.hdnRequestStaffOrExtPartyID.Value) : 0;
                fireProtectionInfo.ResponsibleStaffOrExtPartyID = this.hdnResponsibleStaffOrExtPartyID.Value.Length > 0 ? Convert.ToInt32(this.hdnResponsibleStaffOrExtPartyID.Value) : 0;
                fireProtectionInfo.AmendTimeReason = this.hdnDateTimeReason.Value;
                fireProtectionInfo.Description = this.txtRemarks.Text;
                fireProtectionInfo.ResponsiblePersonID = ViewState["ReponsiblePersonID"] != null ? Convert.ToInt32(ViewState["ReponsiblePersonID"].ToString()) : 0;
                fireProtectionInfo.RequestPersonID = ViewState["RequestPersonID"] != null ? Convert.ToInt32(ViewState["RequestPersonID"].ToString()) : 0;
                fireProtectionInfo.CoorindatorPersonID = ViewState["CoordinatorPersonID"] != null ? Convert.ToInt32(ViewState["CoordinatorPersonID"]) : 0;

                //Add by gordon 20150707 U95
                fireProtectionInfo.RestoreCHUBBID = ViewState["RestoreCHUBB"] != null ? Convert.ToInt32(ViewState["RestoreCHUBB"]) : 0;
                fireProtectionInfo.RestoreCHUBB = txtRestoreCHUBB.Text;
                fireProtectionInfo.RestoreHandleByID = string.IsNullOrEmpty(ddlRestoreHandleBy.SelectedValue) ? 0 : int.Parse(ddlRestoreHandleBy.SelectedValue);
                fireProtectionInfo.ResponsiblePersonID = int.Parse(ddlHandledby.SelectedValue);

                fireProtectionInfo.RestoreTime = this.lblCompleteRestoreTime.Text.Trim().Length > 0 ? this.ConvertToDateTime(this.lblCompleteRestoreTime.Text.Trim()) : DateTime.MinValue;
                //fireProtectionInfo.EventCompleteTime = this.lblCompleteRestoreTime.Text.Trim().Length > 0 ? this.ConvertToDateTime(this.lblCompleteRestoreTime.Text.Trim()) : DateTime.MinValue;
                fireProtectionInfo.FlagRestore = this.chkRestoreNormal.Checked;
                //fireProtectionInfo.FlagComplete = this.chkRestoreNormal.Checked;
                fireProtectionInfo.StationEventFirelInkID = this.StationEventFirelinkID;
                fireProtectionInfo.ExtPartyStaffSnapShotID = this.hdnExtPartyStaffSnapShotID.Value.Trim().Length > 0 ? Convert.ToInt32(this.hdnExtPartyStaffSnapShotID.Value.Trim()) : 0;
                fireProtectionInfo.LastUpdateTime = MTRC.ODMS.DAL.COM.Util.GetCurrentSystemTime();

                /* Issue 167:update by Gordon 2015/05/11 */
                if (!chkRestoreNormal.Checked)
                {
                    fireProtectionInfo.EventStatusID = 1;
                }
                /******************************************/

                if (this.CalledBy == 1)
                {
                    #region From Fire Protection

                    DataTable dt = GetFireZoneGroupStatusTable();
                    ArrayList list = DataTableConvertToFireZoneGroup(dt);

                    if (this.chkRestoreNormal.Checked)
                    {
                        fireProtectionInfo.RestoreTime = this.ConvertToDateTime(lblCompleteRestoreTime.Text);
                        fireProtectionInfo.FlagRestore = true;

                        bool existIsolete = false;

                        //------Exist Isolete Fire Zone Group-------
                        for (int i = 0; i < list.Count; i++)
                        {
                            Model.SOM.Event.StationEventFireZoneGroupInfo itemFireZoneGroupInfo = (Model.SOM.Event.StationEventFireZoneGroupInfo)list[i];

                            if (itemFireZoneGroupInfo.FireZoneGrpIDStatusID == 2)
                            {
                                existIsolete = true;

                                break;
                            }
                        }
                        //----------------End-------------------

                        //set complete.
                        if (this.lblCompleteRestoreTime.Text.Trim().Length > 0 && !existIsolete)
                        {
                            fireProtectionInfo.FlagComplete = true;
                            fireProtectionInfo.EventStatusID = 2;
                            fireProtectionInfo.EventCompleteTime = this.ConvertToDateTime(lblCompleteRestoreTime.Text);
                        }
                    }

                    BLL.SOM.Event.FireProtection.Update(fireProtectionInfo, list, this.ODMUser);
                    hdnStationEventLastUpdataTime.Value = fireProtectionInfo.LastUpdateTime.ToString();
                    //Response.Redirect("FireProtectionEntry.aspx?StationEventID=" + this.StationEventID + "&Action=Edit"); //modify 2008-10-24

                    #endregion
                }
                else if (this.CalledBy == 2)
                {
                    #region From AR

                    DataTable dtFireZoneGroup = GetFireZoneGroup();

                    if (this.chkRestoreNormal.Checked)
                    {
                        fireProtectionInfo.RestoreTime = this.ConvertToDateTime(lblCompleteRestoreTime.Text);
                        fireProtectionInfo.FlagRestore = true;


                        //------Exist Isolete Fire Zone Group-------

                        bool existIsolete = false;
                        foreach (DataRow dr in dtFireZoneGroup.Rows)
                        {
                            if (dr["FireZoneGrpIDStatusID"].ToString().Trim().Length > 0)
                            {
                                if (Convert.ToInt16(dr["FireZoneGrpIDStatusID"]) == 2)
                                {
                                    existIsolete = true;

                                    break;
                                }
                            }
                        }

                        //-------------End---------------

                        //set complete.
                        if (this.lblCompleteRestoreTime.Text.Trim().Length > 0 && !existIsolete)
                        {
                            fireProtectionInfo.FlagComplete = true;
                            fireProtectionInfo.EventStatusID = 2;
                            this.EventStatusID = 2;
                            fireProtectionInfo.EventCompleteTime = this.ConvertToDateTime(lblCompleteRestoreTime.Text);
                        }

                        //------------ Add at 2009-01-06 actionlog 0851 -----------
                        if (existIsolete)
                        {
                            fireProtectionInfo.StationEventID = 1;
                            this.EventStatusID = 1;
                            if (this.chkRestoreNormal.Checked && this.lblCompleteRestoreTime.Text.Length > 1)
                            {
                                fireProtectionInfo.FlagComplete = false;
                                fireProtectionInfo.RestoreTime = DateTime.MinValue;

                                this.chkRestoreNormal.Checked = false;
                                this.lblCompleteRestoreTime.Text = "";
                            }
                        }
                        //---------- End add at 2009-01-06 actionlog 0851 ---------
                    }

                    //update by gordon 20150818 U125.1
                    //BLL.SOM.Event.FireProtection.UpdateTempData_EventData(Convert.ToInt32(this.TempID), Convert.ToInt32(this.StationEventID), GetStationEvent(), GetStationEventFirelink(), dtFireZoneGroup, GetStationEventPerson(), GetStationEventAmendTime());
                    BLL.SOM.Event.FireProtection.UpdateTempData_EventData(Convert.ToInt32(this.TempID), Convert.ToInt32(this.StationEventID), GetStationEvent(), GetStationEventFirelink(), dtFireZoneGroup, GetStationEventPerson(), GetStationEventAmendTime(), GetEventTimeAndUserGroupID());

                    if (flagNew)
                    {
                        string q_StatffID = Request.QueryString["StatffID"] != null ? Request.QueryString["StatffID"].ToString() : "";
                        string q_txtIsolationDateTime = Request.QueryString["txtIsolationDateTime"] != null ? Request.QueryString["txtIsolationDateTime"].ToString() : "";
                        string q_imgRequesSrc = Request.QueryString["imgRequesSrc"] != null ? Request.QueryString["imgRequesSrc"].ToString() : "";
                        string q_txtRequestByName = Request.QueryString["txtRequestByName"] != null ? Request.QueryString["txtRequestByName"].ToString() : "";
                        string q_txtRequestByDept = Request.QueryString["txtRequestByDept"] != null ? Request.QueryString["txtRequestByDept"].ToString() : "";
                        string q_txtRequestByOU = Request.QueryString["txtRequestByOU"] != null ? Request.QueryString["txtRequestByOU"].ToString() : "";
                        string q_txtRequestByContactNumber = Request.QueryString["txtRequestByContactNumber"] != null ? Request.QueryString["txtRequestByContactNumber"].ToString() : "";
                        string q_txtIsolationDuration = Request.QueryString["txtIsolationDuration"] != null ? Request.QueryString["txtIsolationDuration"].ToString() : "";
                        string q_lblEstimatedIsolationDate = Request.QueryString["lblEstimatedIsolationDate"] != null ? Request.QueryString["lblEstimatedIsolationDate"].ToString() : "";
                        string q_chkHandoverCheck = Request.QueryString["chkHandoverCheck"] != null ? Request.QueryString["chkHandoverCheck"].ToString() : "";
                        string q_txtHandoverNote = Request.QueryString["txtHandoverNote"] != null ? Request.QueryString["txtHandoverNote"].ToString() : "";
                        string q_hdnInitDateTime = Request.QueryString["hdnInitDateTime"] != null ? Request.QueryString["hdnInitDateTime"].ToString() : "";
                        string q_hdnRequestStaffOrExtPartyID = Request.QueryString["hdnRequestStaffOrExtPartyID"] != null ? Request.QueryString["hdnRequestStaffOrExtPartyID"].ToString() : "";

                        string redirectUrl = "PopupARFirePortection.aspx?Action=New&ParentStationEventID=" + this.ParentEventID + "&ParentEventNo=" + this.ParentEventNo + "&tempID=" + this.TempID + "&StationEventID=-1" + "&StatffID=" + q_StatffID + "&txtIsolationDateTime=" + q_txtIsolationDateTime + "&imgRequesSrc=" + q_imgRequesSrc + "&txtRequestByName=" + q_txtRequestByName + "&txtRequestByDept=" + q_txtRequestByDept + "&txtRequestByOU=" + q_txtRequestByOU + "&txtRequestByContactNumber=" + q_txtRequestByContactNumber + "&txtIsolationDuration=" + q_txtIsolationDuration + "&lblEstimatedIsolationDate=" + q_lblEstimatedIsolationDate + "&chkHandoverCheck=" + q_chkHandoverCheck + "&txtHandoverNote=" + q_txtHandoverNote + "&hdnInitDateTime=" + q_hdnInitDateTime + "&hdnRequestStaffOrExtPartyID=" + q_hdnRequestStaffOrExtPartyID;

                        Response.Redirect(redirectUrl);
                    }

                    //Response.Redirect("FireProtectionEntry.aspx?StationEventID=" + this.StationEventID + "&Action=Edit&tempID=" + this.TempID + "&ParentStationEventID=" + this.ParentEventID + "&ParentStationEventNo=" + this.ParentEventNo);

                    #endregion
                }

                //this.PAlert(GetMessage("COM_UpdateResultSuccessfully")); //modify 2008-10-24

                #endregion
            }

            this.ddlFireLink.Enabled = false;
            this.ddlStation.Enabled = false;
        }

        protected void btnNew_Click()
        {
            this.ddlFireLink.Enabled = true;
            Response.Redirect("FireProtectionEntry.aspx?Action=New");

            //FunctionItemSetting();
        }

        public void btnCopyAsNew_Click()
        {
            this.Action = 1;
            this.ParentEventID = 0;
            this.ParentEventNo = "";

            this.btnAmendEventTime.Attributes.Add("style", "background-color: inherit;");

            //---------------- Add at 2008-12-8 ----------------------

            //Model.Security.StaffInfo staffInfo = DAL.Security.Staff.GetStaffInfo(this.ODMUser.StaffInfoId);
            //this.hdnResponsibleStaffOrExtPartyID.Value = staffInfo.StaffInfoID.ToString();
            //this.hdnResponsibleByID.Value = staffInfo.StaffID;
            //this.ddlHandledby.SelectedItem.Text = staffInfo.StaffName;
            this.ddlHandledby.SelectedValue = this.ODMUser.ID.ToString();

            //--------------- End add at 2008-12-8 -------------------



            //------------Copy status and clare restore status------

            DataTable dt = GetFireZoneGroup();


            string strSet = "";

            foreach (DataRow dr in dt.Rows)
            {
                if (Convert.ToInt32(dr["FireZoneGrpIDStatusID"].ToString()) == 3)
                {
                    strSet = strSet + dr["FireZoneGrpID"].ToString() + ":1,";
                }
                else
                {
                    strSet = strSet + dr["FireZoneGrpID"].ToString() + ":" + dr["FireZoneGrpIDStatusID"].ToString() + ",";
                }
            }

            this.txtFireZonePanelData.Value = strSet;


            //--------------------end-----------------------------

            CreateFireZoneGroupPanel();

            //----------------Clear some show items.--------------------            
            this.lblParentEventNo.Visible = false;
            this.lblAdmissionRegistry.Visible = false;
            this.lblGoToAdmission.Visible = false;
            this.btnSelectRequest.Visible = true;
            //this.imgSelectResponsible.Visible = true;
            this.lblNOShow.Visible = false;
            this.imgAssetLoanEventStatus.Visible = false;
            this.imgAssetLoanEventHighLight.Visible = false;
            this.chkRestoreNormal.Checked = false;
            this.lblCompleteRestoreTime.Text = "";


            //------add at 2008-11-20-----

            this.StationEventID = 0;
            this.ReadOnly = false;

            this.ParameterSetting();

            //set can amend time.
            if (DAL.Security.User.CanFunctionItemAccess("M140302_F4", this.ODMUser.UserProfileID, this.MenuID))
            {
                this.CanAmendTime = true;
            }

            //-----end add at 2008-11-20---

            //---------------Clear some input items.-----------

            //clear isolate time.
            this.InitDateTime = DAL.COM.Util.GetCurrentSystemTime();
            this.txtIsolationDateTime.Text = this.FormatDateTime(this.InitDateTime, true);
            this.hdnDateTimeReason.Value = this.FormatDateTime(this.InitDateTime, true);
            this.txtIsolationDuration.Text = "0";
            this.hdnInitDateTime.Value = this.FormatDateTime(this.InitDateTime, true);
            this.lblEstimatedIsolationDate.Text = this.FormatDateTime(this.InitDateTime, true);

            //clear request by information.
            this.imgRequest.ImageUrl = @"../../Images/SOM/StaffType_AddHoc.gif";
            this.txtRequestByID.Text = "";
            this.hdnStaffType.Value = "4";
            this.hdnRequestStaffOrExtPartyID.Value = "";
            this.txtRequestByName.Text = "";
            this.txtRequestByDept.Text = "";
            this.txtRequestByOU.Text = "";
            this.txtRequestByContactNumber.Text = "";
            this.hdnResponsibleByType.Value = "1";

            this.chkRestoreNormal.Enabled = false; //add at 2009-02-04

            //Add By Gordon 2015/06/15
            //Ref To Req18.4
            chkHandoverNot.Checked = false;
            txtHandoverNote.Text = string.Empty;
            txtHandoverNote.Enabled = false;

            //add by hzx,on 20090110
            //if ((!DAL.Security.User.CanFunctionItemAccess("M140302_F1", this.ODMUser.UserProfileID, this.MenuID)) && (!DAL.Security.User.CanFunctionItemAccess("M140302_F2", this.ODMUser.UserProfileID, this.MenuID)))
            //{
            //    this.ddlStation.Enabled = false;
            //}

            FunctionItemSetting();
            //update by benson 2015-09-15  U205 begin
            ddlRestoreHandleBy.SelectedIndex = 0;
            txtRestoreCHUBB.Text = "";
            //update by benson 2015-09-15  U205 end

            //update by gordon U51
            this.chkHandoverNot.Enabled = true;
            this.HaveParent = false;
            this.lblRestoreCHUBB.Text = GetLabel("SOM_FireLinkRestoreCHUBB", true);
            this.lblRestoreHandleBy.Text = GetLabel("SOM_FireLinkRestoreHandleBy", true);
        }

        protected void btnReturn_Click()
        {

        }

        public void btnVoid_Click()
        {
            Model.SOM.Event.StationEventInfo stationEvent = new MTRC.ODMS.Model.SOM.Event.StationEventInfo();



            //add by SQB action log 0478 begin...
            //DAL.SOM.Event.StationEventDa.Update(stationEvent, ref stationEventNo, 3);
            //stationEvent.StationEventID = this.StationEventID;
            //stationEvent.LastUpdUser = this.ODMUser.ID;
            //stationEvent.FlagObsolete = true;
            //string stationEventNo = stationEvent.EventNo;

            stationEvent.StationEventID = this.StationEventID;
            //update by gordon 20151020 U247
            //stationEvent.LocationID = this.ODMUser.StationID;
            stationEvent.LocationID = this.ODMUser.LocationID;
            stationEvent.EventStatusID = 3;
            stationEvent.LastUpdUser = this.ODMUser.ID;
            stationEvent.LastUpdTime = MTRC.ODMS.DAL.COM.Util.GetCurrentSystemTime();
            // remove by dylan 20151118 for u276 try catch
            // add by dylan 20151111 for add try catch
            //try
            //{
            MTRC.ODMS.DAL.SOM.Event.StationEventDa.DeleteEvent(stationEvent);
            //add by SQB action log 0478 end...
            string addScript = "location.href='" + Request.RawUrl + "'";
            this.Alert(this.GetMessage("SaveSuccessfully"), 10, addScript);
            //}
            //catch (Exception ex)
            //{
            //    APJ.Util.Log.WindowLog.Log(this.GetLabel("SOM_FirePortectionExceptionTitle", true) + ex.Message.Replace('"', '\''), APJ.Util.Log.LogType.Error, this.ODMUser.Name);
            //    this.PAlert(this.GetMessage("SOM_FirePortectionException"));
            //}

            //Response.Redirect("FireProtectionEntry.aspx?StationEventID=" + this.StationEventID + "&Action=Edit");
            //Response.Redirect("PopupARFirePortection.aspx?StationEventID=" + this.StationEventID + "&Action=Edit&tempID=" + this.TempID + "&ParentStationEventID=" + this.ParentEventID + "&ParentStationEventNo=" + this.ParentEventNo);

            //string xmlData = BLL.SOM.Event.FireProtection.CreateDataSetXml(this.LangCode, 68);
        }

        #endregion

        #endregion

        /// <summary>
        /// add by gordon 20150902 U70
        /// </summary>
        public int StationItemsCount
        {
            get
            {
                int count = 0;
                foreach (ListItem li in ddlStation.Items)
                {
                    if (li.Enabled)
                        count += 1;
                }

                return count;
            }
        }

        /// <summary>
        /// CanRestoreFireLinkOrZoneGroup Req13.5
        /// Add by gordon 20150630
        /// </summary>
        /// <param name="can">Can</param>
        public void CanRestoreFireLinkOrZoneGroup(bool can)
        {
            chkRestoreNormal.Enabled = (can && rblStatus.SelectedValue != "1");
            chkRestoreAll.Enabled = can;
            ReadOnly = !can;
            CanChangeStatus = can;
        }

        /// <summary>
        /// CanFindLocation Req13.5
        /// Add by gordon 20150630
        /// </summary>
        /// <param name="locationId">locationId</param>
        /// <param name="canAccessAll">canAccessAll</param>
        /// <returns></returns>
        public bool CanFindLocation(int locationId, bool canAccessAll)
        {
            bool flag = true;
            //update by gordon 20151020 U247
            //DataTable dt = DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, canAccessAll, Convert.ToInt16(LangCode), this.ODMUser.StationID);
            DataTable dt = DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, canAccessAll, Convert.ToInt16(LangCode), this.ODMUser.LocationID);
            DataRow[] rows = dt.Select("LocationID=" + locationId.ToString());
            flag = rows.Length > 0;

            return flag;
        }
    }
}
